浏览代码

Merge remote-tracking branch 'origin/master' into 8.1

Roc 2 年之前
父节点
当前提交
f18b366ff7
共有 78 个文件被更改,包括 583 次插入22125 次删除
  1. 3 5
      go.mod
  2. 235 29
      go.sum
  3. 40 0
      main.go
  4. 4 146
      models/chart.go
  5. 0 163
      models/data_manage/base_from_smm.go
  6. 0 125
      models/data_manage/base_from_trade_index.go
  7. 0 253
      models/data_manage/chart_classify.go
  8. 0 56
      models/data_manage/chart_edb_mapping.go
  9. 2 833
      models/data_manage/chart_info.go
  10. 0 27
      models/data_manage/chart_info_log.go
  11. 0 253
      models/data_manage/edb_classify.go
  12. 2 67
      models/data_manage/edb_data_base.go
  13. 0 176
      models/data_manage/edb_data_calculate.go
  14. 0 28
      models/data_manage/edb_data_calculate_ljztbpj.go
  15. 0 3
      models/data_manage/edb_data_calculate_tbz.go
  16. 0 1
      models/data_manage/edb_data_calculate_tcz.go
  17. 0 539
      models/data_manage/edb_data_calculate_time_shift.go
  18. 0 35
      models/data_manage/edb_data_calculate_zjpj.go
  19. 0 423
      models/data_manage/edb_data_cffex.go
  20. 0 423
      models/data_manage/edb_data_dl.go
  21. 0 336
      models/data_manage/edb_data_gl.go
  22. 0 178
      models/data_manage/edb_data_lt.go
  23. 0 329
      models/data_manage/edb_data_lz.go
  24. 0 321
      models/data_manage/edb_data_manual.go
  25. 0 171
      models/data_manage/edb_data_pb.go
  26. 0 727
      models/data_manage/edb_data_quarter.go
  27. 0 423
      models/data_manage/edb_data_sh.go
  28. 0 423
      models/data_manage/edb_data_shfe.go
  29. 0 165
      models/data_manage/edb_data_ths.go
  30. 0 166
      models/data_manage/edb_data_wind.go
  31. 0 547
      models/data_manage/edb_data_ys.go
  32. 0 423
      models/data_manage/edb_data_zz.go
  33. 3 871
      models/data_manage/edb_info.go
  34. 2 582
      models/data_manage/edb_info_calculate.go
  35. 0 591
      models/data_manage/edb_info_calculate_bp.go
  36. 0 510
      models/data_manage/edb_info_calculate_hbz.go
  37. 0 527
      models/data_manage/edb_info_calculate_hcz.go
  38. 0 892
      models/data_manage/edb_info_calculate_ljztbpj.go
  39. 0 785
      models/data_manage/edb_info_calculate_ljzzy.go
  40. 0 71
      models/data_manage/edb_info_calculate_mapping.go
  41. 0 617
      models/data_manage/edb_info_calculate_nszydpjjs.go
  42. 0 1031
      models/data_manage/edb_info_calculate_tbz.go
  43. 0 1010
      models/data_manage/edb_info_calculate_tcz.go
  44. 0 4
      models/data_manage/edb_info_calculate_time_shift.go
  45. 0 686
      models/data_manage/edb_info_calculate_zjpj.go
  46. 0 29
      models/data_manage/edb_info_log.go
  47. 0 86
      models/data_manage/edb_info_updates.go
  48. 0 112
      models/data_manage/gl_data.go
  49. 0 8
      models/data_manage/holiday.go
  50. 0 108
      models/data_manage/lz_data.go
  51. 0 25
      models/data_manage/manual.go
  52. 0 156
      models/data_manage/manual_classify.go
  53. 0 112
      models/data_manage/manual_user.go
  54. 0 576
      models/data_manage/my_chart.go
  55. 0 25
      models/data_manage/my_chart_log.go
  56. 0 1
      models/data_manage/refresh_calculate.go
  57. 0 19
      models/data_manage/search_keyword.go
  58. 0 130
      models/data_manage/smm_data.go
  59. 5 34
      models/db.go
  60. 2 0
      models/edb_data_base.go
  61. 7 8
      models/share_chart_refresh_log.go
  62. 0 1318
      models/target.go
  63. 30 0
      services/alarm_msg/alarm_msg.go
  64. 152 0
      services/data/base_edb_lib.go
  65. 0 69
      services/data/base_from_smm.go
  66. 0 86
      services/data/chart_classify.go
  67. 36 511
      services/data/chart_info.go
  68. 0 119
      services/data/edb_classify.go
  69. 0 9
      services/data/edb_data.go
  70. 0 169
      services/data/edb_data_pb.go
  71. 0 166
      services/data/edb_data_ths.go
  72. 0 155
      services/data/edb_data_wind.go
  73. 0 1639
      services/data/edb_info.go
  74. 0 355
      services/data/edb_info_calculate.go
  75. 0 127
      services/data/edb_info_elastic.go
  76. 9 0
      utils/config.go
  77. 8 1
      utils/constants.go
  78. 43 1
      utils/logs.go

+ 3 - 5
go.mod

@@ -3,14 +3,12 @@ module hongze/hongze_chart_lib
 go 1.16
 
 require (
-	github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02 // indirect
 	github.com/beego/bee/v2 v2.0.2
-	github.com/beego/beego/v2 v2.0.1
+	github.com/beego/beego/v2 v2.0.2
 	github.com/go-sql-driver/mysql v1.6.0
+	github.com/google/go-cmp v0.5.6 // indirect
 	github.com/nosixtools/solarlunar v0.0.0-20211112060703-1b6dea7b4a19
-	github.com/olivere/elastic/v7 v7.0.30
 	github.com/rdlucklib/rdluck_tools v1.0.2
-	github.com/shopspring/decimal v1.3.1
-	github.com/yidane/formula v0.0.0-20210902154546-0782e1736717
+	golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 )

+ 235 - 29
go.sum

@@ -14,26 +14,37 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
+github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
+github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
+github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
+github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
+github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
 github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
+github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
 github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
 github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
-github.com/antlr/antlr4 v0.0.0-20211218165449-dd623ecc2f02 h1:2F3iKoAzV2fu8GVaXt+eLIuAuoPKwQkEPydI1OwZ2hs=
-github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02 h1:o2oaBQGTzO+xNh12e7xWkphNe7H2DTiWv1ml9a2P9PQ=
-github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
+github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
+github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
+github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
 github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
+github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
 github.com/astaxie/beego v1.12.3 h1:SAQkdD2ePye+v8Gn1r4X6IKZM1wd28EyUOVQ3PDSOOQ=
 github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA=
-github.com/aws/aws-sdk-go v1.42.23/go.mod h1:gyRszuZ/icHmHAVE4gc/r+cfCmhA1AD+vqfWbgI+eHs=
+github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
+github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
+github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
 github.com/beego/bee/v2 v2.0.2 h1:xWARyIqdnnbNMDBDUdb6Gvr9S/yGXC6Ni43kKdS1/eg=
 github.com/beego/bee/v2 v2.0.2/go.mod h1:rfZa899qLAF8SYBRvE7mWNPZTU7/qysOBhaCLmZrMX4=
 github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE=
 github.com/beego/beego/v2 v2.0.1/go.mod h1:8zyHi1FnWO1mZLwTn62aKRIZF/aIKvkCBB2JYs+eqQI=
+github.com/beego/beego/v2 v2.0.2 h1:Mx2MWMHJN1oFBHewHWyIhR25tXB9IPceIK8X7OuMdZM=
+github.com/beego/beego/v2 v2.0.2/go.mod h1:4pxstbxq+2qE8IUzFsVK8X9BsqfRjbp7ohbapTrTLho=
 github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
 github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
@@ -43,27 +54,44 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
 github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
 github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
 github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
+github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
 github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
+github.com/casbin/casbin v1.9.1/go.mod h1:z8uPsfBJGUsnkagrt3G8QvjgTKFMBJ32UP8HpZllfog=
+github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
+github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
 github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
 github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
 github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
 github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
+github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
+github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
+github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
 github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
 github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
+github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
 github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
+github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
 github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
+github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
+github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
 github.com/cosiner/argv v0.1.0/go.mod h1:EusR6TucWKX+zFgtdUsKT2Cvg45K5rtpCcWz4hK06d8=
 github.com/couchbase/go-couchbase v0.0.0-20200519150804-63f3cdb75e0d/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
+github.com/couchbase/go-couchbase v0.1.0/go.mod h1:+/bddYDxXsf9qt0xpDUtRR47A2GjaXmGGAqQ/k3GJ8A=
 github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
+github.com/couchbase/gomemcached v0.1.3/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
 github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
+github.com/couchbase/goutils v0.1.0/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
 github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
 github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -71,18 +99,30 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
 github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
+github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
+github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
+github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
+github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
+github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
 github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
+github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
 github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
+github.com/elastic/go-elasticsearch/v6 v6.8.10/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
 github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
 github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
+github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
+github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
+github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
+github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
 github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
 github.com/flosch/pongo2 v0.0.0-20200529170236-5abacdfa4915/go.mod h1:fB4mx6dzqFinCxIf3a7Mf5yLk+18Bia9mPAnuejcvDA=
-github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
+github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
+github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
@@ -94,27 +134,36 @@ github.com/go-delve/delve v1.5.0/go.mod h1:c6b3a1Gry6x8a4LGCe/CWzrocrfaHvkUxCj3k
 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
+github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
+github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
+github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
 github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
 github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
+github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
+github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
+github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
-github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
-github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
 github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
 github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
 github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
@@ -125,6 +174,9 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
@@ -136,7 +188,9 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
 github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
 github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-dap v0.2.0/go.mod h1:5q8aYQFnHOAZEMP+6vmq25HKYAEwE+LF5yh7JKrrhSQ=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -144,17 +198,28 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi
 github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
 github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
+github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
+github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
+github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
+github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
+github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
 github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
+github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
+github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
 github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
+github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
 github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
+github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
 github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
 github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
@@ -165,6 +230,7 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
 github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
 github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
 github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
 github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
@@ -176,14 +242,17 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
 github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
 github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
-github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
-github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
+github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
 github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
-github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
-github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
+github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
 github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
+github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
+github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
 github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
+github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
 github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
 github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
@@ -191,8 +260,10 @@ github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9/go.mod h1:W54LbzXuIE0b
 github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
 github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
 github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
+github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -204,14 +275,19 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDuKuq+uX4v1fulaMbA/7ZLLhjc85h7chZGBCQ=
 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
 github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
+github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
+github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
 github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
-github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
-github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
 github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
 github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
+github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
@@ -227,71 +303,118 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
 github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
 github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8=
 github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
+github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
+github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
+github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
+github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
+github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
+github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
+github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/nosixtools/solarlunar v0.0.0-20211112060703-1b6dea7b4a19 h1:LhWT2dBuNkYexwRSsPpYh67e0ikmH1ebBDaVkGHoMts=
 github.com/nosixtools/solarlunar v0.0.0-20211112060703-1b6dea7b4a19/go.mod h1:LjhyrWzOLJ9l1azMoNr9iCvfNrHEREqvJHzSLQcD0/o=
+github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
+github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
-github.com/olivere/elastic v1.0.1 h1:UeafjZg+TifCVPhCJNPof0pUHig6vbXuJEbC/A+Ouo0=
-github.com/olivere/elastic v6.2.37+incompatible h1:UfSGJem5czY+x/LqxgeCBgjDn6St+z8OnsCuxwD3L0U=
-github.com/olivere/elastic/v7 v7.0.30 h1:MyDWv+ZSn+56AOmqr69Sg4EFaBdGMpWFEK5zuqaL8AM=
-github.com/olivere/elastic/v7 v7.0.30/go.mod h1:idEQxe7Es+Wr4XAuNnJdKeMZufkA9vQprOIFck061vg=
+github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
+github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
 github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
 github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
+github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
+github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
+github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
+github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
+github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
 github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
+github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
+github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
+github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
+github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
+github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
+github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
 github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
+github.com/pelletier/go-toml v1.9.2/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
+github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
 github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
 github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
+github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
+github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
 github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
 github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
 github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
+github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
 github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U=
 github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
+github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
+github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ=
+github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
 github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
+github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
 github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
+github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
 github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
+github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
 github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
 github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
+github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ=
+github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
 github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
+github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
 github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
 github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
+github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
 github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
+github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
+github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
+github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
 github.com/rdlucklib/rdluck_tools v1.0.2 h1:Xf1khfttpAh4D1jtMVE5OxLXhFUaDnvG74vZH7FSZQY=
 github.com/rdlucklib/rdluck_tools v1.0.2/go.mod h1:9Onw9o4w19C8KE5lxb8GyxgRBbZweRVkQSc79v38EaA=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
+github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
+github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
+github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
-github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
-github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
+github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
+github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
+github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
 github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
 github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
@@ -300,61 +423,86 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
 github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
 github.com/smartwalle/pongo2render v1.0.1/go.mod h1:MGnTzND7nEMz7g194kjlnw8lx/V5JJlb1hr5kDXEO0I=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
-github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
-github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
+github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
 github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
+github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
+github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
+github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
 github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
+github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
+github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
+github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
 github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
-github.com/yidane/formula v0.0.0-20210902154546-0782e1736717 h1:9CTJJpdISGxMAELfVlprj5kZEsJEaNAWiobv8ZAd72U=
-github.com/yidane/formula v0.0.0-20210902154546-0782e1736717/go.mod h1:9/dQiKiN04yPMdgsuFmKGuI2Hdp6OmFV9gSWS1col6g=
 github.com/ylywyn/jpush-api-go-client v0.0.0-20190906031852-8c4466c6e369/go.mod h1:Nv7wKD2/bCdKUFNKcJRa99a+1+aSLlCRJFriFYdjz/I=
+github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
 github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
 go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
+go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
+go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
 go.etcd.io/etcd v3.3.25+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI=
+go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
+go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
+go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=
+go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
+go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
 go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
 go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
-go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
+go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.starlark.net v0.0.0-20190702223751-32f345186213/go.mod h1:c1/X6cHgvdXj6pUlmWKMkuqRnW4K8x2vwt6JAaaircg=
+go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
+go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
+go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
+go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
 go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
+go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
 go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
+go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
 go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
+go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
 golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
+golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -370,13 +518,16 @@ golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHl
 golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
+golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
 golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
 golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
 golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
+golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -385,6 +536,7 @@ golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73r
 golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -393,15 +545,21 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn
 golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
 golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
 golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
 golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
-golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
 golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY=
 golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
+golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -409,6 +567,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -416,6 +576,7 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -425,27 +586,42 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
 golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
+golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -470,20 +646,26 @@ golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtn
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
+golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58 h1:1Bs6RVeBFtLZ8Yi1Hk07DiOqzvwLD/4hln4iahvFlag=
 golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
 google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
 google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
 google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
 google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
 google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
@@ -492,19 +674,28 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn
 google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
 google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
 google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
 google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
 google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
+google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
+google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
 google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
+google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
 google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
+google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
 google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
 google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
 google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
-google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
+google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
+google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -516,6 +707,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
@@ -524,8 +718,10 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
+gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
 gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
@@ -533,15 +729,22 @@ gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3M
 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
 gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
 gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -550,3 +753,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
 honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
 rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
+sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
+sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
+sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=

+ 40 - 0
main.go

@@ -1,9 +1,16 @@
 package main
 
 import (
+	"fmt"
 	_ "hongze/hongze_chart_lib/routers"
+	"hongze/hongze_chart_lib/services/alarm_msg"
+	"hongze/hongze_chart_lib/utils"
+	"runtime"
+	"time"
 
+	"github.com/beego/beego/v2/adapter/logs"
 	beego "github.com/beego/beego/v2/server/web"
+	"github.com/beego/beego/v2/server/web/context"
 )
 
 func main() {
@@ -11,6 +18,39 @@ func main() {
 		beego.BConfig.WebConfig.DirectoryIndex = true
 		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
+	beego.BConfig.RecoverFunc = Recover
 
 	beego.Run()
 }
+
+func Recover(ctx *context.Context, conf *beego.Config) {
+	if err := recover(); err != nil {
+		if err == beego.ErrAbort {
+			return
+		}
+		if !beego.BConfig.RecoverPanic {
+			panic(err)
+		}
+		stack := ""
+		msg := fmt.Sprintf("The request url is  %v", ctx.Input.URL())
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		msg = fmt.Sprintf("Handler crashed with error %v", err)
+		stack += msg + "</br>"
+		logs.Critical(msg)
+		for i := 1; ; i++ {
+			_, file, line, ok := runtime.Caller(i)
+			if !ok {
+				break
+			}
+			logs.Critical(fmt.Sprintf("%s:%d", file, line))
+			stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
+		}
+		//go utils.SendEmail(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05"), stack, utils.EmailSendToUsers)
+		go alarm_msg.SendAlarmMsg(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05")+"<br/>"+stack, 3)
+	}
+	return
+}

+ 4 - 146
models/chart.go

@@ -3,7 +3,7 @@ package models
 import (
 	"errors"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
+	"github.com/beego/beego/v2/client/orm"
 	"hongze/hongze_chart_lib/utils"
 	"strconv"
 	"time"
@@ -33,8 +33,7 @@ type ChartInfo struct {
 }
 
 func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT * FROM chart_info WHERE unique_code=? `
 	err = o.Raw(sql, uniqueCode).QueryRow(&item)
 	return
@@ -68,8 +67,7 @@ type ChartEdbInfoMapping struct {
 }
 
 func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT a.*,b.source_name,b.source,b.edb_code,b.edb_name,b.frequency,b.unit,b.start_date,b.end_date,b.modify_time,b.edb_type
              FROM chart_edb_mapping AS a
 			 INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
@@ -110,151 +108,11 @@ func GetEdbDataList(source, endInfoId int, startDate, endDate string) (list []*E
 	}
 	sql += ` ORDER BY data_time ASC  `
 	sql = fmt.Sprintf(sql, tableName)
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
 	return
 }
 
-//指标季度数据计算(公历转农历)
-func AddCalculateQuarterV4(dataList []*EdbDataList) (result *EdbDataResult, err error) {
-	var errMsg string
-	defer func() {
-		if errMsg != "" {
-			fmt.Println("errMsg:", errMsg)
-		}
-	}()
-	result = new(EdbDataResult)
-	var yearArr []int
-	yearMap := make(map[int]int)
-	var cureentDate time.Time
-	for k, v := range dataList {
-		dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-		if err != nil {
-			errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-			return result, err
-		}
-		if k == len(dataList)-1 {
-			cureentDate = dateTime
-		}
-		year := dateTime.Year()
-		if _, ok := yearMap[year]; !ok {
-			yearArr = append(yearArr, year)
-		}
-		yearMap[year] = year
-	}
-	//排序
-	fmt.Println(yearArr)
-	thisYear := cureentDate.Year()
-	thisMonth := int(cureentDate.Month())
-
-	fmt.Println("thisMonth:", thisMonth)
-	//sort.Ints(yearArr)
-	fmt.Println("yearArr:", yearArr)
-	fmt.Println("thisYear:", thisYear)
-
-	for ky, vy := range yearArr {
-		fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
-		if thisMonth < 11 {
-			currentYearCjnl := strconv.Itoa(thisYear) + "-01-01"               //当前年份春节农历
-			currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
-			currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-
-			fmt.Println(ky, vy)
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-
-			fmt.Println("day:", day)
-			fmt.Println("currentYearCjgl:", currentYearCjgl, "preYearCjgl:", preYearCjgl)
-
-			items := new(EdbDataItems)
-			items.Year = preYear
-			for _, v := range dataList {
-				dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-				if err != nil {
-					errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-					return result, err
-				}
-
-				newDate := dateTime.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-				fmt.Println("line 467:", newDate, selectDate)
-				if newDate.Before(selectDate) {
-					timestamp := newDate.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = newDate.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			result.List = append(result.List, items)
-		} else {
-			fmt.Println(ky, vy)
-			nextYear := thisYear + 1
-			nextYearCjnl := strconv.Itoa(nextYear) + "-01-01"            //当前年份春节农历
-			nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
-
-			nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-
-			fmt.Println("day:", day)
-			items := new(EdbDataItems)
-			items.Year = preYear
-			for _, v := range dataList {
-				dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-				if err != nil {
-					errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-					return result, err
-				}
-				newDate := dateTime.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-
-				if newDate.Before(selectDate) {
-					timestamp := newDate.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = newDate.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			result.List = append(result.List, items)
-		}
-	}
-	return
-}
-
 type EdbDataItems struct {
 	Items []*EdbDataList
 	Year  int

+ 0 - 163
models/data_manage/base_from_smm.go

@@ -1,163 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type BaseFromSmm struct {
-	BaseFromSmmId int `orm:"column(base_from_smm_id);pk"`
-	Aid           int
-	Name          string
-	Interface     string
-	ApiUpdate     int
-	ApiUpdateType string
-	ApiType       int
-	ApiTypeAll    string
-	Type1         string `orm:"column(type_1)"`
-	Type2         string `orm:"column(type_2)"`
-	Type3         string `orm:"column(type_3)"`
-	ApiStartTime  string
-	ApiUpdateTime string
-	StartTime     string
-	FinishTime    string
-	AuthModule    string
-	AuthLang      string
-	ApiLabel      string
-	Enable        string
-	EditPerson    string
-	EditTime      string
-	AuthDur       int
-	AuthDurType   string
-}
-
-func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_smm `
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
-func GetBaseFromSmmBySmmCode(smmCode string) (item *BaseFromSmm, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_smm WHERE interface=?`
-	err = o.Raw(sql, smmCode).QueryRow(&item)
-	return
-}
-
-type BaseFromSmmIndex struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
-	Interface          string
-	Name               string
-	IndexCode          string
-	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
-	Frequency          string
-	Unit               string
-	ApiStartTime       string
-	ApiUpdateTime      string
-	StartTime          string
-	FinishTime         string
-	CreateTime         time.Time
-	ModifyTime         time.Time
-}
-
-func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_smm_index `
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
-type BaseFromSmmData struct {
-	SmmDataId          int `orm:"column(smm_data_id);pk"`
-	BaseFromSmmIndexId int
-	IndexCode          string
-	DataTime           string
-	Value              string
-	CreateTime         time.Time
-	ModifyTime         time.Time
-	DataTimestamp      int64
-}
-
-func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-func GetBaseFromSmmDataAll() (list []*BaseFromSmmData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_smm_data `
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
-func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
-	_, err = o.Raw(sql, value, smmDataId).Exec()
-	return
-}
-
-func GetBaseFromSmmIndexBySmmCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
-	_, err = o.Raw(sql, smmCode).QueryRows(&list)
-	return
-}
-
-func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
-	err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId int, minDate, maxDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
-	_, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
-	return
-}
-
-func GetBaseFromSmmDataAllByIndexCode(indexCode string) (list []*BaseFromSmmData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_smm_data WHERE index_code=? `
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetBaseFromSmmIndexByIndexCode(indexCode string) (list *BaseFromSmmIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM base_from_smm_index WHERE index_code=? `
-	err = o.Raw(sql, indexCode).QueryRow(&list)
-	return
-}

+ 0 - 125
models/data_manage/base_from_trade_index.go

@@ -1,125 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type BaseFromTradeShanghaiIndex struct {
-	BaseFromTradeShangHaiIndexId int `orm:"column(base_from_trade_shanghai_index_id);pk"`
-	Rank                         int
-	DealShortName                string
-	DealName                     string
-	DealCode                     string
-	DealValue                    string
-	DealChange                   string
-	BuyShortName                 string
-	BuyName                      string
-	BuyCode                      string
-	BuyValue                     string
-	BuyChange                    string
-	SoldShortName                string
-	SoldName                     string
-	SoldCode                     string
-	SoldValue                    string
-	SoldChange                   string
-	Frequency                    string
-	ClassifyName                 string
-	ClassifyType                 string
-	CreateTime                   time.Time
-	ModifyTime                   time.Time
-	DataTime                     string
-}
-type BaseFromTradeCffexIndex struct {
-	BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_index_id);pk"`
-	Rank                         int
-	DealShortName                string
-	DealName                     string
-	DealCode                     string
-	DealValue                    string
-	DealChange                   string
-	BuyShortName                 string
-	BuyName                      string
-	BuyCode                      string
-	BuyValue                     string
-	BuyChange                    string
-	SoldShortName                string
-	SoldName                     string
-	SoldCode                     string
-	SoldValue                    string
-	SoldChange                   string
-	Frequency                    string
-	ClassifyName                 string
-	ClassifyType                 string
-	CreateTime                   time.Time
-	ModifyTime                   time.Time
-	DataTime                     string
-}
-
-type BaseFromTradeIneIndex struct {
-	BaseFromTradeIneIndexId int `orm:"column(base_from_trade_ine_index_id);pk"`
-	Rank                         int
-	DealShortName                string
-	DealName                     string
-	DealCode                     string
-	DealValue                    string
-	DealChange                   string
-	BuyShortName                 string
-	BuyName                      string
-	BuyCode                      string
-	BuyValue                     string
-	BuyChange                    string
-	SoldShortName                string
-	SoldName                     string
-	SoldCode                     string
-	SoldValue                    string
-	SoldChange                   string
-	Frequency                    string
-	ClassifyName                 string
-	ClassifyType                 string
-	CreateTime                   time.Time
-	ModifyTime                   time.Time
-	DataTime                     string
-}
-
-func GetBaseFromTradeIndexByParam(exchange, date, classifyName, classifyType string) (list []*BaseFromTradeShanghaiIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	if classifyName == ""{
-		sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=?"
-		_, err = o.Raw(sql, date).QueryRows(&list)
-		return
-	}else if classifyType == ""{
-		sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=? and classify_name=? ORDER BY classify_type,rank"
-		_, err = o.Raw(sql, date, classifyName).QueryRows(&list)
-		return
-	}else {
-		sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=? and classify_name=? and classify_type=?"
-		_, err = o.Raw(sql, date, classifyName, classifyType).QueryRows(&list)
-		return
-	}
-}
-
-func GetExchangeClassify(exchange string) (classifyName []*string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := "SELECT DISTINCT classify_name FROM base_from_trade_"+exchange+"_index ORDER BY CONVERT(classify_name using gbk) DESC"
-	_, err = o.Raw(sql).QueryRows(&classifyName)
-	return
-}
-
-func GetLatestDate(exchange string) (date []*BaseFromTradeIneIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := "SELECT * FROM base_from_trade_"+exchange+"_index ORDER BY data_time desc limit 1"
-	_, err = o.Raw(sql).QueryRows(&date)
-	return
-}
-
-func GetExchangeClassifyContract(exchange, Classify, dataTime string) (classifyName []*string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := "SELECT DISTINCT classify_type FROM base_from_trade_"+exchange+"_index where classify_name=? and data_time=?"
-	_, err = o.Raw(sql, Classify, dataTime).QueryRows(&classifyName)
-	return
-}

+ 0 - 253
models/data_manage/chart_classify.go

@@ -1,253 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type ChartClassify struct {
-	ChartClassifyId   int       `orm:"column(chart_classify_id);pk"`
-	ChartClassifyName string    `description:"分类名称"`
-	ParentId          int       `description:"父级id"`
-	HasData           int       `description:"是否含有指标数据"`
-	CreateTime        time.Time `description:"创建时间"`
-	ModifyTime        time.Time `description:"修改时间"`
-	SysUserId         int       `description:"创建人id"`
-	SysUserRealName   string    `description:"创建人姓名"`
-	Level             int       `description:"层级"`
-	UniqueCode        string    `description:"唯一编码"`
-	Sort              int       `description:"排序字段,越小越靠前,默认值:10"`
-}
-
-func AddChartClassify(item *ChartClassify) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type AddChartClassifyReq struct {
-	ChartClassifyName string `description:"分类名称"`
-	ParentId          int    `description:"父级id,第一级传0"`
-	Level             int    `description:"层级,第一级传0,其余传上一级的层级"`
-}
-
-func GetChartClassifyCount(chartClassifyName string, parentId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND chart_classify_name=? `
-	err = o.Raw(sql, parentId, chartClassifyName).QueryRow(&count)
-	return
-}
-
-type EditChartClassifyReq struct {
-	ChartClassifyName string `description:"分类名称"`
-	ChartClassifyId   int    `description:"分类名称"`
-}
-
-func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-func GetChartClassifyCountById(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-func EditChartClassify(classifyId int, chartClassifyName string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `UPDATE chart_classify SET chart_classify_name=?,modify_time=NOW() WHERE chart_classify_id=? `
-	_, err = o.Raw(sql, chartClassifyName, classifyId).Exec()
-	return
-}
-
-type DeleteChartClassifyReq struct {
-	ChartClassifyId int `description:"分类id"`
-	ChartInfoId     int `description:"指标id"`
-}
-
-func GetChartInfoCountByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM chart_info AS a
-				WHERE a.chart_classify_id IN(
-				SELECT t.chart_classify_id FROM 
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
-					 (SELECT @pid := ?) pd 
-				WHERE FIND_IN_SET(parent_id, @pid) > 0 
-				  AND @pid := CONCAT(@pid, ',', chart_classify_id) 
-				UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
-				)AS t
-				) `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-func DeleteChartClassify(classifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` DELETE FROM chart_classify
-				WHERE chart_classify_id IN(
-				SELECT t.chart_classify_id FROM
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
-				(SELECT @pid := ?) pd
-				WHERE FIND_IN_SET(parent_id, @pid) > 0
-				AND @pid := CONCAT(@pid, ',', chart_classify_id)
-				UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
-				)AS t
-				) `
-	_, err = o.Raw(sql, classifyId).Exec()
-	return
-}
-
-func GetChartClassifyByParentId(parentId int) (items []*ChartClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc`
-	_, err = o.Raw(sql, parentId).QueryRows(&items)
-	return
-}
-
-func GetChartClassifyAll() (items []*ChartClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_classify WHERE parent_id<>0  order by sort asc,chart_classify_id asc`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type ChartClassifyItems struct {
-	ChartClassifyId   int `description:"分类id"`
-	ChartInfoId       int `description:"指标id"`
-	ChartClassifyName string
-	ParentId          int
-	Level             int    `description:"层级"`
-	Sort              int    `description:"排序字段,越小越靠前,默认值:10"`
-	UniqueCode        string `description:"唯一编码"`
-	Source            int    `description:"来源id"`
-	SourceName        string `description:"来源名称"`
-	SysUserId         int    `description:"创建人id"`
-	SysUserRealName   string `description:"创建人姓名"`
-	DateType          int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate         string `description:"自定义开始日期"`
-	EndDate           string `description:"自定义结束日期"`
-	ChartType         int    `description:"生成样式:1:曲线图,2:季节性图"`
-	Calendar          string `description:"公历/农历"`
-	SeasonStartDate   string `description:"季节性图开始日期"`
-	SeasonEndDate     string `description:"季节性图开始日期"`
-	Children          []*ChartClassifyItems
-}
-
-type ChartClassifyListResp struct {
-	AllNodes []*ChartClassifyItems
-}
-
-type ChartClassifyDeleteCheckResp struct {
-	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
-	TipsMsg      string `description:"提示信息"`
-}
-
-type ChartClassifyDeleteCheckReq struct {
-	ChartClassifyId int `description:"分类id"`
-	ChartInfoId     int `description:"指标id"`
-}
-
-func GetChartClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM (
-			SELECT rd.*
-			FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
-				 (SELECT @pid := ?) pd 
-			WHERE FIND_IN_SET(parent_id, @pid) > 0 
-			  AND @pid := CONCAT(@pid, ',', chart_classify_id) 
-			UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
-			)AS t
-			WHERE t.chart_classify_id<>? `
-	err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
-	return
-}
-
-func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_classify WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&item)
-	return
-}
-
-// MoveChartClassifyReq 移动图表分类请求参数
-type MoveChartClassifyReq struct {
-	ClassifyId       int `description:"分类id"`
-	ParentClassifyId int `description:"父级分类id"`
-	PrevClassifyId   int `description:"上一个兄弟节点分类id"`
-	NextClassifyId   int `description:"下一个兄弟节点分类id"`
-}
-
-// GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
-func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
-	err = o.Raw(sql, parentId).QueryRow(&item)
-	return
-}
-
-// UpdateChartClassifySortByParentId 根据图表父类id更新排序
-func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
-	if classifyId > 0 {
-		sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
-	}
-	_, err = o.Raw(sql, parentId, nowSort).Exec()
-	return
-}
-
-// Update 更新图表分类基础信息
-func (chartClassify *ChartClassify) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Update(chartClassify, cols...)
-	return
-}
-
-// GetChartClassifyMaxSort 获取图表分类下最大的排序数
-func GetChartClassifyMaxSort(parentId int) (sort int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT Max(sort) AS sort FROM chart_classify WHERE parent_id=? `
-	err = o.Raw(sql, parentId).QueryRow(&sort)
-	return
-}
-
-type ChartClassifyView struct {
-	ChartClassifyId   int       `orm:"column(chart_classify_id);pk"`
-	ChartClassifyName string    `description:"分类名称"`
-	ParentId          int       `description:"父级id"`
-}
-
-func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}

+ 0 - 56
models/data_manage/chart_edb_mapping.go

@@ -1,56 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type ChartEdbMapping struct {
-	ChartEdbMappingId int       `orm:"column(chart_edb_mapping_id);pk"`
-	ChartInfoId       int       `description:"图表id"`
-	EdbInfoId         int       `description:"指标id"`
-	CreateTime        time.Time `description:"创建时间"`
-	ModifyTime        time.Time `description:"修改时间"`
-	UniqueCode        string    `description:"唯一编码"`
-	MaxData           float64   `description:"上限"`
-	MinData           float64   `description:"下限"`
-	IsOrder           bool      `description:"true:正序,false:逆序"`
-	IsAxis            int       `description:"true:左轴,false:右轴"`
-	EdbInfoType       int       `description:"true:标准指标,false:领先指标"`
-	LeadValue         int       `description:"领先值"`
-	LeadUnit          string    `description:"领先单位"`
-	ChartStyle        string    `description:"图表类型"`
-	ChartColor        string    `description:"颜色"`
-	ChartWidth        float64   `description:"线条大小"`
-}
-
-func AddChartEdbMapping(items []*ChartEdbMapping) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.source_name,b.source,b.edb_code,b.edb_name,b.frequency,b.unit,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code
-             FROM chart_edb_mapping AS a
-			 INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
-			 WHERE chart_info_id=? 
-             ORDER BY chart_edb_mapping_id ASC `
-	_, err = o.Raw(sql, chartInfoId).QueryRows(&list)
-	return
-}
-
-func GetChartEdbMappingListByEdbInfoId(edbInfoStr string) (list []*ChartEdbInfoMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT *
-             FROM edb_info
-			 WHERE edb_info_id IN(` + edbInfoStr + `)
-			ORDER BY FIELD(edb_info_id,` + edbInfoStr + `)
-              `
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}

+ 2 - 833
models/data_manage/chart_info.go

@@ -1,729 +1,13 @@
 package data_manage
 
 import (
-	"errors"
 	"fmt"
+	"github.com/beego/beego/v2/client/orm"
 	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"strconv"
-	"strings"
-	"time"
 )
 
-type ChartInfo struct {
-	ChartInfoId     int    `orm:"column(chart_info_id);pk"`
-	ChartName       string `description:"来源名称"`
-	ChartClassifyId int    `description:"图表分类id"`
-	SysUserId       int
-	SysUserRealName string
-	UniqueCode      string `description:"图表唯一编码"`
-	CreateTime      time.Time
-	ModifyTime      time.Time
-	DateType        int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate       string `description:"自定义开始日期"`
-	EndDate         string `description:"自定义结束日期"`
-	IsSetName       int    `description:"设置名称"`
-	EdbInfoIds      string `description:"指标id"`
-	ChartType       int    `description:"生成样式:1:曲线图,2:季节性图"`
-	Calendar        string `description:"公历/农历"`
-	SeasonStartDate string `description:"季节性图开始日期"`
-	SeasonEndDate   string `description:"季节性图开始日期"`
-	ChartImage      string `description:"图表图片"`
-	Sort            int    `description:"排序字段,数字越小越排前面"`
-	LeftMin         string `description:"图表左侧最小值"`
-	LeftMax         string `description:"图表左侧最大值"`
-	RightMin        string `description:"图表右侧最小值"`
-	RightMax        string `description:"图表右侧最大值"`
-}
-
-func AddChartInfo(item *ChartInfo) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type ChartInfoItem struct {
-	ChartInfoId     int    `description:"图表id"`
-	ChartName       string `description:"图表名称"`
-	ChartClassifyId int    `description:"图表分类"`
-}
-
-//用于分类展示
-func GetChartInfoAll() (items []*ChartClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
-             unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
-            FROM chart_info ORDER BY sort asc,create_time ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//用于分类展示
-func GetChartInfoAllList() (items []*ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT *
-            FROM chart_info ORDER BY create_time ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//图表检索数据
-type ChartInfoSearch struct {
-	EdbCode   string `description:"图表编码"`
-	StartDate string `description:"起始日期"`
-	EndDate   string `description:"终止日期"`
-	DataList  []*EdbInfoSearchData
-}
-
-type ChartInfoSearchData struct {
-	DataTime string  `description:"数据日期"`
-	Value    float64 `description:"数据"`
-}
-
-type ChartInfoSearchResp struct {
-	SearchItem *EdbInfoSearch `description:"图表分类"`
-	Status     int            `description:"1:数据已存在于弘则数据库,2:新数据"`
-}
-
-func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
-	err = o.Raw(sql, chartInfoId).QueryRow(&item)
-	return
-}
-
-func GetChartInfoViewById(chartInfoId int) (item *ChartInfoView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
-	err = o.Raw(sql, chartInfoId).QueryRow(&item)
-	return
-}
-
-type SaveChartInfoReq struct {
-	ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
-	ChartInfoId      int              `description:"图表id,新增时传0"`
-	DateType         int              `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
-	StartDate        string           `description:"自定义开始日期"`
-	EndDate          string           `description:"自定义结束日期"`
-	Calendar         string           `description:"公历/农历"`
-	SeasonStartDate  string           `description:"季节性图开始日期"`
-	SeasonEndDate    string           `description:"季节性图开始日期"`
-	LeftMin          string           `description:"图表左侧最小值"`
-	LeftMax          string           `description:"图表左侧最大值"`
-	RightMin         string           `description:"图表右侧最小值"`
-	RightMax         string           `description:"图表右侧最大值"`
-}
-
-type ChartSaveItem struct {
-	EdbInfoId   int     `description:"指标id"`
-	MaxData     float64 `description:"上限"`
-	MinData     float64 `description:"下限"`
-	IsOrder     bool    `description:"true:正序,false:逆序"`
-	IsAxis      int     `description:"1:左轴,0:右轴"`
-	EdbInfoType int     `description:"1:标准指标,0:领先指标"`
-	LeadValue   int     `description:"领先值"`
-	LeadUnit    string  `description:"领先单位"`
-	ChartStyle  string  `description:"图表类型"`
-	ChartColor  string  `description:"颜色"`
-	ChartWidth  float64 `description:"线条大小"`
-}
-
-func DeleteChartInfoAndData(chartInfoId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
-	_, err = o.Raw(sql, chartInfoId).Exec()
-	if err != nil {
-		return
-	}
-	sql = ` DELETE FROM  chart_edb_mapping WHERE chart_info_id=? `
-	_, err = o.Raw(sql, chartInfoId).Exec()
-	return
-}
-
-func GetChartInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-type EditChartInfoReq struct {
-	ChartInfoId      int              `description:"图表ID"`
-	ChartName        string           `description:"图表名称"`
-	ChartClassifyId  int              `description:"分类id"`
-	ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
-	ChartType        int              `description:"生成样式:1:曲线图,2:季节性图"`
-	DateType         int              `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
-	StartDate        string           `description:"自定义开始日期"`
-	EndDate          string           `description:"自定义结束日期"`
-	Calendar         string           `description:"公历/农历"`
-	SeasonStartDate  string           `description:"季节性图开始日期"`
-	SeasonEndDate    string           `description:"季节性图开始日期"`
-	LeftMin          string           `description:"图表左侧最小值"`
-	LeftMax          string           `description:"图表左侧最大值"`
-	RightMin         string           `description:"图表右侧最小值"`
-	RightMax         string           `description:"图表右侧最大值"`
-}
-
-func ModifyChartInfo(item *EditChartInfoReq) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  chart_info
-			SET
-			  chart_name =?,
-			  chart_classify_id = ?,
-              is_set_name=1,
-			  modify_time = NOW()
-			WHERE chart_info_id = ?`
-	_, err = o.Raw(sql, item.ChartName, item.ChartClassifyId, item.ChartInfoId).Exec()
-	return
-}
-
-type ChartInfoList struct {
-	ChartInfoId          int    `orm:"column(chart_info_id);pk"`
-	ChartName            string `description:"来源名称"`
-	ChartChartClassifyId int    `description:"图表分类id"`
-	SysUserId            int
-	SysUserRealName      string
-	UniqueCode           string `description:"图表唯一编码"`
-	CreateTime           time.Time
-	ModifyTime           time.Time
-	EdbInfoList          []*EdbInfoList
-}
-
-type ChartInfoListResp struct {
-	Paging *paging.PagingItem
-	Item   *ChartInfoList
-}
-
-func GetChartInfoByCondition(condition string, pars []interface{}) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&item)
-	return
-}
-
-func GetChartInfoByNewest() (item *EdbInfoList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE 1=1 ORDER BY modify_time DESC LIMIT 1 `
-	err = o.Raw(sql).QueryRow(&item)
-	return
-}
-
-func ModifyChartInfoModifyTime(chartInfoId int64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  chart_info SET modify_time = NOW() WHERE chart_info_id = ? `
-	_, err = o.Raw(sql, chartInfoId).Exec()
-	return
-}
-
-type MoveChartInfoReq struct {
-	ChartInfoId     int `description:"图表ID"`
-	PrevChartInfoId int `description:"上一个图表ID"`
-	NextChartInfoId int `description:"下一个图表ID"`
-	ChartClassifyId int `description:"分类id"`
-}
-
-func MoveChartInfo(chartInfoId, classifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  chart_info
-			SET
-			  chart_classify_id = ?
-			WHERE chart_info_id = ?`
-	_, err = o.Raw(sql, classifyId, chartInfoId).Exec()
-	return
-}
-
-type DeleteChartInfoReq struct {
-	ChartInfoId int `description:"图表ID"`
-}
-
-type EdbDataList struct {
-	EdbDataId     int     `description:" 指标数据ID"`
-	EdbInfoId     int     `description:"指标ID"`
-	DataTime      string  //`json:"-" description:"数据日期"`
-	DataTimestamp int64   `description:"数据日期"`
-	Value         float64 `description:"数据值"`
-}
-
-func GetEdbDataList(source, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
-	tableName := GetEdbDataTableName(source)
-	if tableName == "" {
-		err = errors.New("无效的渠道:" + strconv.Itoa(source))
-		list = make([]*EdbDataList, 0)
-		return list, err
-	}
-	var pars []interface{}
-	sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
-	if startDate != "" {
-		sql += ` AND data_time>=? `
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		sql += ` AND data_time<=? `
-		pars = append(pars, endDate)
-	}
-
-	sql += ` ORDER BY data_time ASC `
-	sql = fmt.Sprintf(sql, tableName)
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
-	return
-}
-
-func GetEdbDataLunarList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
-	tableName := "edb_data_quarter"
-	sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,2) AS value,data_timestamp FROM %s WHERE edb_info_id=? AND data_time>=? AND data_time<=? ORDER BY data_time ASC `
-	sql = fmt.Sprintf(sql, tableName)
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sql, endInfoId, startDate, endDate).QueryRows(&list)
-	return
-}
-
-func GetEdbDataListMinAndMax(source, endInfoId int, startDate, endDate string) (min_data, max_data float64, err error) {
-	tableName := GetEdbDataTableName(source)
-	sql := `SELECT min(value) AS min_data,max(value) AS max_data FROM %s WHERE edb_info_id=? `
-	var pars []interface{}
-	var condition string
-
-	if startDate != "" {
-		condition += ` AND data_time>=? `
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += ` AND data_time<=? `
-		pars = append(pars, endDate)
-	}
-
-	sql = fmt.Sprintf(sql, tableName)
-	o := orm.NewOrm()
-	o.Using("data")
-
-	if condition != "" {
-		sql += condition
-	}
-
-	err = o.Raw(sql, endInfoId, pars).QueryRow(&min_data, &max_data)
-	return
-}
-
-type ChartEdbInfoMapping struct {
-	EdbInfoId         int     `description:"指标id"`
-	SourceName        string  `description:"来源名称"`
-	Source            int     `description:"来源id"`
-	EdbCode           string  `description:"指标编码"`
-	EdbName           string  `description:"指标名称"`
-	EdbType           int     `description:"指标类型:1:基础指标,2:计算指标"`
-	Frequency         string  `description:"频率"`
-	Unit              string  `description:"单位"`
-	StartDate         string  `description:"起始日期"`
-	EndDate           string  `description:"终止日期"`
-	ModifyTime        string  `description:"指标最后更新时间"`
-	ChartEdbMappingId int     `description:"图表指标id"`
-	ChartInfoId       int     `description:"图表id"`
-	MaxData           float64 `description:"上限"`
-	MinData           float64 `description:"下限"`
-	IsOrder           bool    `description:"true:正序,false:逆序"`
-	IsAxis            int     `description:"1:左轴,0:右轴"`
-	EdbInfoType       int     `description:"1:标准指标,0:领先指标"`
-	LeadValue         int     `description:"领先值"`
-	LeadUnit          string  `description:"领先单位"`
-	ChartStyle        string  `description:"图表类型"`
-	ChartColor        string  `description:"颜色"`
-	ChartWidth        float64 `description:"线条大小"`
-	LatestDate        string  `description:"数据最新日期"`
-	LatestValue       float64 `description:"数据最新值"`
-	UniqueCode        string  `description:"指标唯一编码"`
-	MinValue          float64 `json:"-" description:"最小值"`
-	MaxValue          float64 `json:"-" description:"最大值"`
-	DataList          interface{}
-}
-
-type QuarterData struct {
-	Year     int
-	DataList []*EdbDataList
-}
-
-type ChartEdbInfoDetailResp struct {
-	EdbInfo *ChartEdbInfoMapping
-}
-
-type ChartInfoDetailResp struct {
-	ChartInfo   *ChartInfoView
-	EdbInfoList []*ChartEdbInfoMapping
-}
-
-func ModifyChartInfoAndMapping(edbInfoIdStr string, req *SaveChartInfoReq, chartType int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if chartType == 1 {
-		sql := ` UPDATE  chart_info
-			SET
-              edb_info_ids=?,
-			  modify_time = NOW(),
-              date_type=?,
-			  start_date=?,
-			  end_date=?,
- 			  left_min=?,
-			  left_max=?,
-			  right_min=?,
-			  right_max=?
-			WHERE chart_info_id = ?`
-		_, err = o.Raw(sql, edbInfoIdStr, req.DateType, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.ChartInfoId).Exec()
-		if err != nil {
-			fmt.Println("UPDATE  chart_info Err:", err.Error())
-			return err
-		}
-	} else {
-		sql := ` UPDATE  chart_info
-			SET
-              edb_info_ids=?,
-			  modify_time = NOW(),
-			  calendar=?,
-			  season_start_date=?,
-			  season_end_date=?,
-			  left_min=?,
-			  left_max=?,
-			  right_min=?,
-			  right_max=?
-			WHERE chart_info_id = ?`
-		_, err = o.Raw(sql, edbInfoIdStr, req.Calendar, req.SeasonStartDate, req.SeasonEndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.ChartInfoId).Exec()
-		if err != nil {
-			fmt.Println("UPDATE  chart_info Err:", err.Error())
-			return err
-		}
-	}
-
-	var edbInfoIdArr []string
-	mapList := make([]*ChartEdbMapping, 0)
-	for _, v := range req.ChartEdbInfoList {
-		edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
-		var count int
-		csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
-		err = o.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
-		if err != nil {
-			fmt.Println("QueryRow Err:", err.Error())
-			return err
-		}
-		if count > 0 {
-			msql := `UPDATE  chart_edb_mapping
-				SET
-                 modify_time = NOW(),
-				 max_data = ?,
-				 min_data = ?,
-				 is_order = ?,
-				 is_axis = ?,
-				 edb_info_type = ?,
-				 lead_value = ?,
-				 lead_unit = ?,
-				 chart_style = ?,
-				 chart_color = ?,
-				 chart_width = ? 
-				WHERE chart_info_id =? AND edb_info_id=? `
-			_, err = o.Raw(msql, v.MaxData, v.MinData, v.IsOrder, v.IsAxis, v.EdbInfoType, v.LeadValue, v.LeadUnit, v.ChartStyle, v.ChartColor, v.ChartWidth, req.ChartInfoId, v.EdbInfoId).Exec()
-			if err != nil {
-				fmt.Println("chart_edb_mapping Err:" + err.Error())
-				return err
-			}
-		} else {
-			mapItem := new(ChartEdbMapping)
-			mapItem.ChartInfoId = req.ChartInfoId
-			mapItem.EdbInfoId = v.EdbInfoId
-			mapItem.CreateTime = time.Now()
-			mapItem.ModifyTime = time.Now()
-			timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-			mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
-			mapItem.MaxData = v.MaxData
-			mapItem.MinData = v.MinData
-			mapItem.IsOrder = v.IsOrder
-			mapItem.IsAxis = v.IsAxis
-			mapItem.EdbInfoType = v.EdbInfoType
-			mapItem.LeadValue = v.LeadValue
-			mapItem.LeadUnit = v.LeadUnit
-			mapItem.ChartStyle = v.ChartStyle
-			mapItem.ChartColor = v.ChartColor
-			mapItem.ChartWidth = v.ChartWidth
-			mapList = append(mapList, mapItem)
-		}
-	}
-	if len(mapList) > 0 {
-		_, err = o.InsertMulti(1, mapList)
-		if err != nil {
-			fmt.Println("AddChartEdbMapping Err:" + err.Error())
-			return err
-		}
-	}
-	if len(edbInfoIdArr) > 0 {
-		edbInfoIdStr := strings.Join(edbInfoIdArr, ",")
-		if edbInfoIdStr != "" {
-			dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id NOT IN(` + edbInfoIdStr + `)`
-			_, err = o.Raw(dsql, req.ChartInfoId).Exec()
-			if err != nil {
-				fmt.Println("delete err:" + err.Error())
-				return err
-			}
-		}
-	}
-	return
-}
-
-func EditChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	var pars []interface{}
-	pars = append(pars, req.ChartName)
-	pars = append(pars, edbInfoIdStr)
-	pars = append(pars, req.ChartType)
-	pars = append(pars, req.ChartClassifyId)
-
-	sql := ` UPDATE  chart_info
-			SET
-			  chart_name =?,
-              edb_info_ids=?,
-			  chart_type=?,
-			  chart_classify_id = ?,
-			  modify_time = NOW()
-			`
-	if calendar != "" {
-		sql += `,calendar = ? `
-		pars = append(pars, calendar)
-	}
-	if dateType > 0 {
-		sql += `,date_type = ? `
-		pars = append(pars, dateType)
-	}
-
-	sql += `,start_date = ? `
-	pars = append(pars, req.StartDate)
-
-	sql += `,end_date = ? `
-	pars = append(pars, req.EndDate)
-
-	sql += `,season_start_date = ? `
-	pars = append(pars, req.SeasonStartDate)
-
-	sql += `,season_end_date = ? `
-	pars = append(pars, req.SeasonEndDate)
-
-	sql += `,left_min = ? `
-	pars = append(pars, req.LeftMin)
-
-	sql += `,left_max = ? `
-	pars = append(pars, req.LeftMax)
-
-	sql += `,right_min = ? `
-	pars = append(pars, req.RightMin)
-
-	sql += `,right_max = ? `
-	pars = append(pars, req.RightMax)
-
-	sql += `WHERE chart_info_id = ?`
-
-	pars = append(pars, req.ChartInfoId)
-	_, err = o.Raw(sql, pars).Exec()
-	if err != nil {
-		fmt.Println("UPDATE  chart_info Err:", err.Error())
-		return err
-	}
-	var edbInfoIdArr []string
-	mapList := make([]*ChartEdbMapping, 0)
-	for _, v := range req.ChartEdbInfoList {
-		edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
-		var count int
-		csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
-		err = o.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
-		if err != nil {
-			fmt.Println("QueryRow Err:", err.Error())
-			return err
-		}
-		if count > 0 {
-			msql := `UPDATE  chart_edb_mapping
-				SET
-                 modify_time = NOW(),
-				 max_data = ?,
-				 min_data = ?,
-				 is_order = ?,
-				 is_axis = ?,
-				 edb_info_type = ?,
-				 lead_value = ?,
-				 lead_unit = ?,
-				 chart_style = ?,
-				 chart_color = ?,
-				 chart_width = ? 
-				WHERE chart_info_id =? AND edb_info_id=? `
-			_, err = o.Raw(msql, v.MaxData, v.MinData, v.IsOrder, v.IsAxis, v.EdbInfoType, v.LeadValue, v.LeadUnit, v.ChartStyle, v.ChartColor, v.ChartWidth, req.ChartInfoId, v.EdbInfoId).Exec()
-			if err != nil {
-				fmt.Println("chart_edb_mapping Err:" + err.Error())
-				return err
-			}
-		} else {
-			mapItem := new(ChartEdbMapping)
-			mapItem.ChartInfoId = req.ChartInfoId
-			mapItem.EdbInfoId = v.EdbInfoId
-			mapItem.CreateTime = time.Now()
-			mapItem.ModifyTime = time.Now()
-			timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-			mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
-			mapItem.MaxData = v.MaxData
-			mapItem.MinData = v.MinData
-			mapItem.IsOrder = v.IsOrder
-			mapItem.IsAxis = v.IsAxis
-			mapItem.EdbInfoType = v.EdbInfoType
-			mapItem.LeadValue = v.LeadValue
-			mapItem.LeadUnit = v.LeadUnit
-			mapItem.ChartStyle = v.ChartStyle
-			mapItem.ChartColor = v.ChartColor
-			mapItem.ChartWidth = v.ChartWidth
-			mapList = append(mapList, mapItem)
-		}
-	}
-	if len(mapList) > 0 {
-		_, err = o.InsertMulti(1, mapList)
-		if err != nil {
-			fmt.Println("AddChartEdbMapping Err:" + err.Error())
-			return err
-		}
-	}
-	if len(edbInfoIdArr) > 0 {
-		edbInfoIdStr := strings.Join(edbInfoIdArr, ",")
-		dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id NOT IN(` + edbInfoIdStr + `)`
-		_, err = o.Raw(dsql, req.ChartInfoId).Exec()
-		if err != nil {
-			fmt.Println("delete err:" + err.Error())
-			return err
-		}
-	}
-	return
-}
-
-func ModifyEdbDatadTimestamp(source, edbDataId int, dataTimestamp int64) (err error) {
-	tableName := GetEdbDataTableName(source)
-	sql := `UPDATE %s SET data_timestamp=? WHERE edb_data_id=? `
-	sql = fmt.Sprintf(sql, tableName)
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sql, dataTimestamp, edbDataId).Exec()
-	return
-}
-
-type AddChartInfoReq struct {
-	ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
-	ChartClassifyId  int              `description:"分类id"`
-	ChartName        string           `description:"图表名称"`
-	ChartType        int              `description:"生成样式:1:曲线图,2:季节性图"`
-	DateType         int              `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
-	StartDate        string           `description:"自定义开始日期"`
-	EndDate          string           `description:"自定义结束日期"`
-	Calendar         string           `description:"公历/农历"`
-	SeasonStartDate  string           `description:"季节性图开始日期"`
-	SeasonEndDate    string           `description:"季节性图开始日期"`
-	LeftMin          string           `description:"图表左侧最小值"`
-	LeftMax          string           `description:"图表左侧最大值"`
-	RightMin         string           `description:"图表右侧最小值"`
-	RightMax         string           `description:"图表右侧最大值"`
-}
-
-type AddChartInfoResp struct {
-	ChartInfoId int    `description:"图表id"`
-	UniqueCode  string `description:"图表唯一编码"`
-	ChartType   int    `description:"生成样式:1:曲线图,2:季节性图"`
-}
-
-//判断图表指标是否已经存在
-func ChartInfoExist(condition, edbInfoIdStr string) (count int, err error) {
-	sql := `SELECT COUNT(1) AS count FROM (
-		SELECT GROUP_CONCAT(edb_info_id ORDER BY edb_info_id ASC  SEPARATOR ',') AS edb_info_id_str 
-		 FROM chart_edb_mapping AS a
-         WHERE 1=1`
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` GROUP BY chart_info_id 
-		)AS t
-		WHERE t.edb_info_id_str=? 
-        GROUP BY t.edb_info_id_str `
-	o := orm.NewOrm()
-	o.Using("data")
-	err = o.Raw(sql, edbInfoIdStr).QueryRow(&count)
-	return
-}
-
-func ChartInfoSearchByKeyWord(KeyWord string) (searchList []*ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info `
-	if KeyWord != "" {
-		sql += `WHERE chart_name LIKE '%` + KeyWord + `%'  `
-	}
-	sql += ` ORDER BY create_time DESC `
-	if KeyWord == "" {
-		sql += ` LIMIT 100 `
-	}
-	_, err = o.Raw(sql).QueryRows(&searchList)
-	return
-}
-
-func GetNextChartInfo(classifyId int) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT b.* FROM chart_classify AS a
-			INNER JOIN chart_info AS b ON a.chart_classify_id=b.chart_classify_id
-			WHERE a.chart_classify_id>?
-			ORDER BY a.chart_classify_id ASC
-			LIMIT 1 `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
 func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 
 	sql := ` SELECT b.* FROM  chart_edb_mapping AS a
 		   INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id 
@@ -773,118 +57,3 @@ func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculate
 	}
 	return
 }
-
-type SetChartInfoImageReq struct {
-	ChartInfoId int    `description:"图表ID"`
-	ImageUrl    string `description:"图表图片地址"`
-}
-
-func EditChartInfoImage(req *SetChartInfoImageReq) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-
-	sql := ` UPDATE  chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
-	_, err = o.Raw(sql, req.ImageUrl, req.ChartInfoId).Exec()
-	if err != nil {
-		fmt.Println("EditChartInfoImage Err:", err.Error())
-		return err
-	}
-
-	return
-}
-
-type ChartInfoDetailFromUniqueCodeResp struct {
-	ChartInfo   *ChartInfoView
-	Status      bool `description:"true:图表存在,false:图表不存在"`
-	EdbInfoList []*ChartEdbInfoMapping
-}
-
-func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE unique_code=? `
-	err = o.Raw(sql, uniqueCode).QueryRow(&item)
-	return
-}
-
-// GetFirstChartInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
-func GetFirstChartInfoByClassifyId(classifyId int) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE chart_classify_id=? order by sort asc,chart_info_id asc limit 1`
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-// UpdateChartInfoSortByClassifyId 根据图表id更新排序
-func UpdateChartInfoSortByClassifyId(classifyId, nowSort, prevChartInfoId int, updateSort string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id=? and sort > ? `
-	if prevChartInfoId > 0 {
-		sql += ` or (chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
-	}
-	_, err = o.Raw(sql, classifyId, nowSort).Exec()
-	return
-}
-
-// Update 更新图表基础信息
-func (chartInfo *ChartInfo) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Update(chartInfo, cols...)
-	return
-}
-
-type ChartInfoView struct {
-	ChartInfoId       int    `orm:"column(chart_info_id);pk"`
-	ChartName         string `description:"来源名称"`
-	ChartClassifyId   int    `description:"图表分类id"`
-	ChartClassifyName string `description:"图表名称"`
-	SysUserId         int
-	SysUserRealName   string
-	UniqueCode        string `description:"图表唯一编码"`
-	CreateTime        time.Time
-	ModifyTime        time.Time
-	DateType          int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate         string `description:"自定义开始日期"`
-	EndDate           string `description:"自定义结束日期"`
-	IsSetName         int    `description:"设置名称"`
-	EdbInfoIds        string `description:"指标id"`
-	ChartType         int    `description:"生成样式:1:曲线图,2:季节性图"`
-	Calendar          string `description:"公历/农历"`
-	SeasonStartDate   string `description:"季节性图开始日期"`
-	SeasonEndDate     string `description:"季节性图开始日期"`
-	ChartImage        string `description:"图表图片"`
-	Sort              int    `description:"排序字段,数字越小越排前面"`
-	IsAdd             bool   `description:"true:已加入我的图库,false:未加入我的图库"`
-	MyChartId         int
-	MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
-	ChartClassify     []*ChartClassifyView
-	EdbEndDate        string `description:"指标最新更新日期"`
-	LeftMin           string `description:"图表左侧最小值"`
-	LeftMax           string `description:"图表左侧最大值"`
-	RightMin          string `description:"图表右侧最小值"`
-	RightMax          string `description:"图表右侧最大值"`
-}
-
-type ImageSvgToPngResp struct {
-	Data struct {
-		ResourceURL string `json:"ResourceUrl"`
-	} `json:"Data"`
-	ErrCode     string `json:"ErrCode"`
-	ErrMsg      string `json:"ErrMsg"`
-	IsSendEmail bool   `json:"IsSendEmail"`
-	Msg         string `json:"Msg"`
-	Ret         int64  `json:"Ret"`
-	Success     bool   `json:"Success"`
-}
-
-// GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
-func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
-	err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
-	return
-}

+ 0 - 27
models/data_manage/chart_info_log.go

@@ -1,27 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type ChartInfoLog struct {
-	ChartInfoLogId  int    `orm:"column(chart_info_log_id);pk"`
-	ChartInfoId     int    `description:"图表id"`
-	ChartName       string `description:"来源名称"`
-	ChartClassifyId int    `description:"图表分类id"`
-	SysUserId       int
-	SysUserRealName string
-	UniqueCode      string `description:"图表唯一编码"`
-	CreateTime      time.Time
-	Content         string `description:"内容"`
-	Status          string `description:"状态"`
-	Method          string `description:"执行方法"`
-}
-
-func AddChartInfoLog(item *ChartInfoLog) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}

+ 0 - 253
models/data_manage/edb_classify.go

@@ -1,253 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type EdbClassify struct {
-	ClassifyId      int       `orm:"column(classify_id);pk"`
-	ClassifyName    string    `description:"分类名称"`
-	ParentId        int       `description:"父级id"`
-	HasData         int       `description:"是否含有指标数据"`
-	CreateTime      time.Time `description:"创建时间"`
-	ModifyTime      time.Time `description:"修改时间"`
-	SysUserId       int       `description:"创建人id"`
-	SysUserRealName string    `description:"创建人姓名"`
-	Level           int       `description:"层级"`
-	UniqueCode      string    `description:"唯一编码"`
-	Sort            int       `description:"排序字段,越小越靠前,默认值:10"`
-}
-
-func AddEdbClassify(item *EdbClassify) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type AddEdbClassifyReq struct {
-	ClassifyName string `description:"分类名称"`
-	ParentId     int    `description:"父级id,第一级传0"`
-	Level        int    `description:"层级,第一级传0,其余传上一级的层级"`
-}
-
-func GetEdbClassifyCount(classifyName string, parentId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT COUNT(1) AS count FROM edb_classify WHERE parent_id=? AND classify_name=? `
-	err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
-	return
-}
-
-type EditEdbClassifyReq struct {
-	ClassifyName string `description:"分类名称"`
-	ClassifyId   int    `description:"分类名称"`
-}
-
-func GetEdbClassifyById(classifyId int) (item *EdbClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM edb_classify WHERE classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-func GetEdbClassifyCountById(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT count(1) AS count FROM edb_classify WHERE classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-func EditEdbClassify(classifyId int, classifyName string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `UPDATE edb_classify SET classify_name=?,modify_time=NOW() WHERE classify_id=? `
-	_, err = o.Raw(sql, classifyName, classifyId).Exec()
-	return
-}
-
-type DeleteEdbClassifyReq struct {
-	ClassifyId int `description:"分类id"`
-	EdbInfoId  int `description:"指标id"`
-}
-
-func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info AS a
-				WHERE a.classify_id IN(
-				SELECT t.classify_id FROM 
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM edb_classify WHERE parent_id IS NOT NULL) rd,
-					 (SELECT @pid := ?) pd 
-				WHERE FIND_IN_SET(parent_id, @pid) > 0 
-				  AND @pid := CONCAT(@pid, ',', classify_id) 
-				UNION SELECT * FROM edb_classify WHERE classify_id = @pid
-				)AS t
-				) `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-func DeleteEdbClassify(classifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` DELETE FROM edb_classify
-				WHERE classify_id IN(
-				SELECT t.classify_id FROM
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM edb_classify WHERE parent_id IS NOT NULL) rd,
-				(SELECT @pid := ?) pd
-				WHERE FIND_IN_SET(parent_id, @pid) > 0
-				AND @pid := CONCAT(@pid, ',', classify_id)
-				UNION SELECT * FROM edb_classify WHERE classify_id = @pid
-				)AS t
-				) `
-	_, err = o.Raw(sql, classifyId).Exec()
-	return
-}
-
-func GetEdbClassifyByParentId(parentId int) (items []*EdbClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_classify WHERE parent_id=?  order by sort asc,classify_id asc`
-	_, err = o.Raw(sql, parentId).QueryRows(&items)
-	return
-}
-
-func GetEdbClassifyAll() (items []*EdbClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_classify WHERE parent_id<>0  order by sort asc,classify_id asc`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type EdbClassifyItems struct {
-	ClassifyId      int `description:"分类id"`
-	EdbInfoId       int `description:"指标id"`
-	ClassifyName    string
-	ParentId        int
-	Level           int    `description:"层级"`
-	Sort            int    `description:"排序字段,越小越靠前,默认值:10"`
-	UniqueCode      string `description:"唯一编码"`
-	Source          int    `description:"来源id"`
-	SourceName      string `description:"来源名称"`
-	SysUserId       int    `description:"创建人id"`
-	SysUserRealName string `description:"创建人姓名"`
-	StartDate       string
-	EdbCode         string
-	EdbType         int `description:"指标类型:1:基础指标,2:计算指标"`
-	Children        []*EdbClassifyItems
-}
-
-type EdbClassifyListResp struct {
-	AllNodes []*EdbClassifyItems
-}
-
-type ClassifyDeleteCheckResp struct {
-	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
-	TipsMsg      string `description:"提示信息"`
-}
-
-type ClassifyDeleteCheckReq struct {
-	ClassifyId int `description:"分类id"`
-	EdbInfoId  int `description:"指标id"`
-}
-
-func GetClassifyCountByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM (
-			SELECT rd.*
-			FROM (SELECT * FROM edb_classify WHERE parent_id IS NOT NULL) rd,
-				 (SELECT @pid := ?) pd 
-			WHERE FIND_IN_SET(parent_id, @pid) > 0 
-			  AND @pid := CONCAT(@pid, ',', classify_id) 
-			UNION SELECT * FROM edb_classify WHERE classify_id = @pid
-			)AS t
-			WHERE t.classify_id<>? `
-	err = o.Raw(sql, classifyId, classifyId).QueryRow(&count)
-	return
-}
-
-type EdbClassifySimplify struct {
-	ClassifyId   int    `description:"分类id"`
-	ClassifyName string `description:"分类名称"`
-	ParentId     int
-}
-
-//递归获取所有目录
-func GetClassifyAllByClassifyId(classifyId int) (resultList []*EdbClassifySimplify, err error) {
-	fmt.Println("185")
-	o := orm.NewOrm()
-	o.Using("data")
-	for {
-		sql := ` SELECT * FROM edb_classify AS a
-			WHERE a.classify_id=? order by sort asc,classify_id asc`
-		item := new(EdbClassifySimplify)
-		err = o.Raw(sql, classifyId).QueryRow(&item)
-		if err != nil {
-			break
-		}
-		if item.ClassifyId > 0 {
-			resultList = append(resultList, item)
-			classifyId = item.ParentId
-		} else {
-			break
-		}
-	}
-	return resultList, err
-}
-
-// MoveEdbClassifyReq 移动分类请求参数
-type MoveEdbClassifyReq struct {
-	ClassifyId       int `description:"分类id"`
-	ParentClassifyId int `description:"父级分类id"`
-	PrevClassifyId   int `description:"上一个兄弟节点分类id"`
-	NextClassifyId   int `description:"下一个兄弟节点分类id"`
-}
-
-// GetFirstEdbClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
-func GetFirstEdbClassifyByParentId(parentId int) (item *EdbClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
-	err = o.Raw(sql, parentId).QueryRow(&item)
-	return
-}
-
-// UpdateEdbClassifySortByParentId 根据父类id更新排序
-func UpdateEdbClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` update edb_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
-	if classifyId > 0 {
-		sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
-	}
-	_, err = o.Raw(sql, parentId, nowSort).Exec()
-	return
-}
-
-// Update 更新分类基础信息
-func (edbClassify *EdbClassify) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Update(edbClassify, cols...)
-	return
-}
-
-// GetEdbClassifyMaxSort 获取分类下最大的排序数
-func GetEdbClassifyMaxSort(parentId int) (sort int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT Max(sort) AS sort FROM edb_classify WHERE parent_id=? `
-	err = o.Raw(sql, parentId).QueryRow(&sort)
-	return
-}

+ 2 - 67
models/data_manage/edb_data_base.go

@@ -1,10 +1,7 @@
 package data_manage
 
 import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
 	"hongze/hongze_chart_lib/utils"
-	"time"
 )
 
 //指标数据->存储表
@@ -60,72 +57,10 @@ func GetEdbDataTableName(source int) (tableName string) {
 		tableName = "edb_data_calculate_ljztbpj"
 	case utils.DATA_SOURCE_LT:
 		tableName = "edb_data_lt"
+	case utils.DATA_SOURCE_COAL:
+		tableName = "edb_data_coal"
 	default:
 		tableName = ""
 	}
 	return
 }
-
-//计算指标->关联的基础指标表
-//func GetEdbInfoCalculateTableName(source int) (tableName string) {
-//	switch source {
-//	case utils.DATA_SOURCE_CALCULATE:
-//		tableName = "edb_info_calculate"
-//	case utils.DATA_SOURCE_CALCULATE_LJZZY:
-//		tableName = "edb_info_calculate_ljzzy"
-//	case utils.DATA_SOURCE_CALCULATE_TBZ:
-//		tableName = "edb_info_calculate_tbz"
-//	case utils.DATA_SOURCE_CALCULATE_TCZ:
-//		tableName = "edb_info_calculate_tcz"
-//	case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
-//		tableName = "edb_info_calculate_nszydpjjs"
-//	case utils.DATA_SOURCE_CALCULATE_HBZ:
-//		tableName = "edb_info_calculate_hbz"
-//	case utils.DATA_SOURCE_CALCULATE_HCZ:
-//		tableName = "edb_info_calculate_hcz"
-//	case utils.DATA_SOURCE_CALCULATE_BP:
-//		tableName = "edb_info_calculate_bp"
-//	default:
-//		tableName = ""
-//	}
-//	return
-//}
-
-type EdbDataBase struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         string
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
-	var pars []interface{}
-	pars = append(pars, edbCode)
-	o := orm.NewOrm()
-	o.Using("data")
-
-	tableName := GetEdbDataTableName(source)
-	sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
-	if limit > 0 {
-		sql += `  LIMIT ?  `
-		pars = append(pars, limit)
-	}
-	sql = fmt.Sprintf(sql, tableName)
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	tableName := GetEdbDataTableName(source)
-	sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
-	sql = fmt.Sprintf(sql, tableName)
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}

+ 0 - 176
models/data_manage/edb_data_calculate.go

@@ -1,176 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/yidane/formula"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataCalculate struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-func AddEdbDataCalculate(items []*EdbDataCalculate) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func AddEdbDataCalculateBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func ModifyEdbDataCalculate(edbInfoId int64, dataTime string, value float64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_calculate SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-func GetEdbDataCalculateByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-//刷新全部数据
-func RefreshAllCalculate(edbInfoIdArr []*EdbInfo, edbInfoId, source int, edbCode, formulaStr, startDate, endDate string, edbInfoIdBytes []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	fmt.Println(startDate, endDate)
-	saveDataMap := make(map[string]map[int]float64)
-	for _, v := range edbInfoIdArr {
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, v.EdbInfoId)
-		if startDate != "" {
-			condition += " AND data_time>=? "
-			pars = append(pars, startDate)
-		}
-		if endDate != "" {
-			condition += " AND data_time<=? "
-			pars = append(pars, endDate)
-		}
-		fmt.Println("v.Source:", v.Source)
-		dataList, err := GetEdbDataListAll(condition, pars, v.Source, 1)
-		if err != nil {
-			return err
-		}
-		dataMap := make(map[string]float64)
-		for _, dv := range dataList {
-			if val, ok := saveDataMap[dv.DataTime]; ok {
-				if _, ok := val[v.EdbInfoId]; !ok {
-					val[v.EdbInfoId] = dv.Value
-				}
-			} else {
-				temp := make(map[int]float64)
-				temp[v.EdbInfoId] = dv.Value
-				saveDataMap[dv.DataTime] = temp
-			}
-		}
-		item := new(CalculateItems)
-		item.EdbInfoId = v.EdbInfoId
-		item.DataMap = dataMap
-	}
-
-	formulaMap := CheckFormula(formulaStr)
-	addSql := ` INSERT INTO edb_data_calculate(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	existDataMap := make(map[string]string)
-	for sk, sv := range saveDataMap {
-		fmt.Println(sk, sv)
-		formulaStr = strings.ToUpper(formulaStr)
-		formulaFormStr := ReplaceFormula(edbInfoIdArr, sv, formulaMap, formulaStr, edbInfoIdBytes)
-		if formulaFormStr != "" {
-			utils.FileLog.Info("formulaFormStr:%s", formulaFormStr)
-			expression := formula.NewExpression(formulaFormStr)
-			calResult, err := expression.Evaluate()
-			if err != nil {
-				err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-			calVal, err := calResult.Float64()
-			if err != nil {
-				err = errors.New("计算失败:获取计算值失败 Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-
-			saveValue := utils.SubFloatToString(calVal, 4)
-			if existVal, ok := dataMap[sk]; !ok {
-				dataTime, _ := time.Parse(utils.FormatDate, sk)
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-
-				if _, existOk := existDataMap[sk]; !existOk {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, sk, timeStr, saveValue)
-					isAdd = true
-				}
-				existDataMap[sk] = sk
-			} else {
-				if existVal != saveValue {
-					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-					sql = fmt.Sprintf(sql, dataTableName)
-					_, err = o.Raw(sql, saveValue, edbInfoId, sk).Exec()
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			fmt.Println("RefreshAllCalculate add Err", err.Error())
-			return
-		}
-	}
-	return
-}

+ 0 - 28
models/data_manage/edb_data_calculate_ljztbpj.go

@@ -1,28 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-// EdbDataCalculateLjztbpj 累计值同比拼接数据结构体
-type EdbDataCalculateLjztbpj struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-// GetAllEdbDataCalculateLjztbpjByEdbInfoId 根据指标id获取全部的数据
-func GetAllEdbDataCalculateLjztbpjByEdbInfoId(edbInfoId int) (items []*EdbDataCalculateLjztbpj, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_calculate_ljztbpj WHERE edb_info_id=? ORDER BY data_time DESC `
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
-	return
-}

+ 0 - 3
models/data_manage/edb_data_calculate_tbz.go

@@ -1,3 +0,0 @@
-package data_manage
-
-

+ 0 - 1
models/data_manage/edb_data_calculate_tcz.go

@@ -1 +0,0 @@
-package data_manage

+ 0 - 539
models/data_manage/edb_data_calculate_time_shift.go

@@ -1,539 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-//时间移位
-
-type EdbInfoCalculateMove struct {
-	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
-	EdbInfoId            int       `description:"指标id"`
-	EdbCode              string    `description:"指标编码"`
-	FromEdbInfoId        int       `description:"计算指标id"`
-	FromEdbCode          string    `description:"计算指标编码"`
-	FromEdbName          string    `description:"计算指标名称"`
-	FromSource           int       `description:"计算指标来源"`
-	FromSourceName       string    `description:"计算指标来源名称"`
-	FromTag              string    `description:"来源指标标签"`
-	Sort                 int       `description:"计算指标名称排序"`
-	CreateTime           time.Time `description:"创建时间"`
-	ModifyTime           time.Time `description:"修改时间"`
-}
-
-//时间移位
-func AddCalculateTimeShift(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateTimeShift")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateTimeShift,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_TIME_SHIFT
-		edbInfo.SourceName = "时间移位"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		edbInfo.MoveType = req.MoveType
-		edbInfo.MoveFrequency = req.MoveFrequency
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_TIME_SHIFT)
-		fmt.Println("dataTableName:" + dataTableName)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-		if err != nil {
-			return 0, err
-		}
-	}
-
-	var shiftDay int
-	formulaInt, _ := strconv.Atoi(req.Formula)
-	switch req.MoveFrequency {
-	case "天":
-		shiftDay = formulaInt
-	case "周":
-		shiftDay = formulaInt * 7
-	case "月":
-		shiftDay = formulaInt * 30
-	case "季":
-		shiftDay = formulaInt * 90
-	case "年":
-		shiftDay = formulaInt * 365
-	default:
-		shiftDay = formulaInt
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_time_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	if req.MoveType == 2 {
-		shiftDay = -shiftDay
-	}
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			newDate := currentDate.AddDate(0, 0, shiftDay)
-			timestamp := newDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
-			isAdd = true
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//环比值
-func EditCalculateTimeShift(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string, oldEdbInfo *EdbInfo) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  move_type=?,
-			  move_frequency=?,
-			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, req.MoveType, req.MoveFrequency, req.Formula, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 || req.MoveType != oldEdbInfo.MoveType || req.MoveFrequency != oldEdbInfo.MoveFrequency || req.Formula != oldEdbInfo.CalculateFormula {
-		if count <= 0 {
-			//删除,计算指标关联的,基础指标的关联关系
-			sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-			_, err = o.Raw(sql, edbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除计算指标关联关系失败,Err:" + err.Error())
-				return
-			}
-			//关联关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = edbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-				calculateMappingItem.FromSource = fromEdbInfo.Source
-				calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-				calculateMappingItem.FromTag = ""
-				calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_TIME_SHIFT
-				calculateMappingItem.SourceName = "时间移位"
-				o.Insert(calculateMappingItem)
-			}
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_time_shift WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-		var shiftDay int
-		formulaInt, _ := strconv.Atoi(req.Formula)
-		switch req.MoveFrequency {
-		case "天":
-			shiftDay = formulaInt
-		case "周":
-			shiftDay = formulaInt * 7
-		case "月":
-			shiftDay = formulaInt * 30
-		case "季":
-			shiftDay = formulaInt * 90
-		case "年":
-			shiftDay = formulaInt * 365
-		default:
-			shiftDay = formulaInt
-		}
-
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		addSql := ` INSERT INTO edb_data_calculate_time_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		existMap := make(map[string]string)
-		dataLen := len(dataList)
-		if req.MoveType == 2 {
-			shiftDay = -shiftDay
-		}
-		for i := 0; i < dataLen; i++ {
-			//当期
-			currentItem := dataList[i]
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			newDate := currentDate.AddDate(0, 0, shiftDay)
-			existKey := edbCode + newDate.Format(utils.FormatDate)
-			if _, ok := existMap[existKey]; !ok {
-				timestamp := newDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				valStr := decimal.NewFromFloat(currentItem.Value).String()
-				addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
-				isAdd = true
-			}
-			existMap[existKey] = currentItem.DataTime
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//变频
-func RefreshCalculateTimeShift(edbInfoId, formulaInt, moveType int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate, moveFrequency string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	var shiftDay int
-	switch moveFrequency {
-	case "天":
-		shiftDay = formulaInt
-	case "周":
-		shiftDay = formulaInt * 7
-	case "月":
-		shiftDay = formulaInt * 30
-	case "季":
-		shiftDay = formulaInt * 90
-	case "年":
-		shiftDay = formulaInt * 365
-	default:
-		shiftDay = formulaInt
-	}
-	if moveType == 2 {
-		shiftDay = -shiftDay
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	addSql := ` INSERT INTO edb_data_calculate_time_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			newDate := currentDate.AddDate(0, 0, -shiftDay)
-			timestamp := newDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateTimeShiftDetail struct {
-	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
-	EdbInfoId            int       `description:"指标id"`
-	EdbCode              string    `description:"指标编码"`
-	FromEdbInfoId        int       `description:"计算指标id"`
-	FromEdbCode          string    `description:"计算指标编码"`
-	FromEdbName          string    `description:"计算指标名称"`
-	FromSource           int       `description:"计算指标来源"`
-	FromSourceName       string    `description:"计算指标来源名称"`
-	FromTag              string    `description:"来源指标标签"`
-	Sort                 int       `description:"计算指标名称排序"`
-	CreateTime           time.Time `description:"创建时间"`
-	ModifyTime           time.Time `description:"修改时间"`
-	StartDate            string    `description:"开始日期"`
-	EndDate              string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateTimeShiftDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-//刷新所有变频数据
-func RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, moveType int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate, moveFrequency string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	var shiftDay int
-	switch moveFrequency {
-	case "天":
-		shiftDay = formulaInt
-	case "周":
-		shiftDay = formulaInt * 7
-	case "月":
-		shiftDay = formulaInt * 30
-	case "季":
-		shiftDay = formulaInt * 90
-	case "年":
-		shiftDay = formulaInt * 365
-	default:
-		shiftDay = formulaInt
-	}
-
-	if moveType == 2 {
-		shiftDay = -shiftDay
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	fmt.Println("existDataMap:", existDataMap)
-	addSql := ` INSERT INTO edb_data_calculate_time_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			newDate := currentDate.AddDate(0, 0, shiftDay)
-
-			timestamp := newDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			if existVal, ok := existDataMap[newDate.Format(utils.FormatDate)]; !ok {
-				isAdd = true
-				addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
-			} else {
-				if existVal != valStr {
-					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-					sql = fmt.Sprintf(sql, dataTableName)
-					_, err = o.Raw(sql, valStr, edbInfoId, newDate.Format(utils.FormatDate)).Exec()
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 35
models/data_manage/edb_data_calculate_zjpj.go

@@ -1,35 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-// EdbDataCalculateZjpj 直接拼接数据结构体
-type EdbDataCalculateZjpj struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-// GetAllEdbDataCalculateZjpjByEdbInfoId 根据指标id获取全部的数据
-func GetAllEdbDataCalculateZjpjByEdbInfoId(edbInfoId int) (items []*EdbDataCalculateZjpj, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_calculate_zjpj WHERE edb_info_id=? ORDER BY data_time DESC `
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
-	return
-}
-
-type EdbDataFromZjpj struct {
-	Date   map[string]int64   `json:"date"`
-	Ticker map[string]string  `json:"ticker"`
-	Field  map[string]string  `json:"field"`
-	Value  map[string]float64 `json:"value"`
-}

+ 0 - 423
models/data_manage/edb_data_cffex.go

@@ -1,423 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type CffexData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-type BaseFromCffexDataSimple struct {
-	Id        int `orm:"column(base_from_trade_cffex_index_id);pk"`
-	DealCode  string
-	BuyCode   string
-	SoldCode  string
-	DataTime  string
-	DealValue string
-	BuyValue  string
-	SoldValue string
-}
-
-type BaseInfoFromCffex struct {
-	DealName string
-	BuyName  string
-	SoldName string
-}
-
-type BaseFromTradeCFFEXIndex struct {
-	BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_index_id);pk"`
-	Rank                      int
-	DealShortName             string
-	DealName                  string
-	DealCode                  string
-	DealValue                 string
-	DealChange                int
-	BuyShortName              string
-	BuyName                   string
-	BuyCode                   string
-	BuyValue                  string
-	BuyChange                 int
-	SoldShortName             string
-	SoldName                  string
-	SoldCode                  string
-	SoldValue                 string
-	SoldChange                int
-	Frequency                 string
-	ClassifyName              string
-	ClassifyType              string
-	CreateTime                time.Time
-	ModifyTime                time.Time
-	DataTime                  string
-}
-
-func GetEdbDataCffexMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_cffex WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
-	return
-}
-
-func GetEdbDataByCffex(edbCode, suffix, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	cffexBaseDataAll, err := GetBaseFromCffexDataAllByIndexCode(edbCode, suffix)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_cffex(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range cffexBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			if suffix == "deal" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
-			} else if suffix == "buy" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
-			} else {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
-			}
-			isAdd = true
-		}
-		if suffix == "deal" {
-			existMap[eDate] = sv.DealValue
-		} else if suffix == "buy" {
-			existMap[eDate] = sv.BuyValue
-		} else {
-			existMap[eDate] = sv.SoldValue
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_CFFEX, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataCffexByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataCffexMaxOrMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-// RefreshEdbDataByCffex 刷新中金所指标数据
-func RefreshEdbDataByCffex(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetCffexDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_cffex(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataCffexByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := itemValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataCffex(int64(edbInfoId), v.DataTime, value)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// RefreshAllEdbDataByCffex 全部刷新中金所
-func RefreshAllEdbDataByCffex(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetCffexDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_cffex(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := itemValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// GetBaseInfoFromCffexByIndexCode 获取指标信息
-func GetBaseInfoFromCffexByIndexCode(indexCode, suffix string) (list []*BaseInfoFromCffex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_cffex_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetCffexDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromCffexDataSimple, err error) {
-	sql := ` SELECT * FROM base_from_trade_cffex_index WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("data")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func AddEdbDataCffexBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataCffexByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_cffex WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetBaseFromCffexDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeCFFEXIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_cffex_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetEdbDataCffexByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_cffex WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataCffex(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_cffex SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}

+ 0 - 423
models/data_manage/edb_data_dl.go

@@ -1,423 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type DlData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-type BaseFromDlDataSimple struct {
-	Id        int `orm:"column(base_from_trade_dalian_index_id);pk"`
-	DealCode  string
-	BuyCode   string
-	SoldCode  string
-	DataTime  string
-	DealValue string
-	BuyValue  string
-	SoldValue string
-}
-
-type BaseInfoFromDl struct {
-	DealName string
-	BuyName  string
-	SoldName string
-}
-
-type BaseFromTradeDalianIndex struct {
-	BaseFromTradeDalianIndexId int `orm:"column(base_from_trade_dalian_index_id);pk"`
-	Rank                       int
-	DealShortName              string
-	DealName                   string
-	DealCode                   string
-	DealValue                  string
-	DealChange                 int
-	BuyShortName               string
-	BuyName                    string
-	BuyCode                    string
-	BuyValue                   string
-	BuyChange                  int
-	SoldShortName              string
-	SoldName                   string
-	SoldCode                   string
-	SoldValue                  string
-	SoldChange                 int
-	Frequency                  string
-	ClassifyName               string
-	ClassifyType               string
-	CreateTime                 time.Time
-	ModifyTime                 time.Time
-	DataTime                   string
-}
-
-func GetEdbDataDlMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_dl WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
-	return
-}
-
-func GetEdbDataByDl(edbCode, suffix, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	dlBaseDataAll, err := GetBaseFromDalianDataAllByIndexCode(edbCode, suffix)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_dl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range dlBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			if suffix == "deal" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
-			} else if suffix == "buy" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
-			} else {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
-			}
-			isAdd = true
-		}
-		if suffix == "deal" {
-			existMap[eDate] = sv.DealValue
-		} else if suffix == "buy" {
-			existMap[eDate] = sv.BuyValue
-		} else {
-			existMap[eDate] = sv.SoldValue
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_DL, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataDlByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataDlMaxOrMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-// RefreshEdbDataByDl 刷新大商所指标数据
-func RefreshEdbDataByDl(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetDlDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_dl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataDlByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := itemValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataDl(int64(edbInfoId), v.DataTime, value)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// RefreshAllEdbDataByDl 全部刷新大商所
-func RefreshAllEdbDataByDl(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetDlDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_dl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := itemValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// GetBaseInfoFromDalianByIndexCode 获取指标信息
-func GetBaseInfoFromDalianByIndexCode(indexCode, suffix string) (list []*BaseInfoFromDl, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_dalian_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetDlDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromDlDataSimple, err error) {
-	sql := ` SELECT * FROM base_from_trade_dalian_index WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("data")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func AddEdbDataDlBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataDlByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_dl WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetBaseFromDalianDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeDalianIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_dalian_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetEdbDataDlByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_dl WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataDl(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_dl SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}

+ 0 - 336
models/data_manage/edb_data_gl.go

@@ -1,336 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-func AddEdbDataGlBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataGlByEdbCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_gl WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetEdbDataGlMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_gl WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-type GlData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-func GetGlDataByTradeCode(condition string, pars []interface{}) (item []*GlData, err error) {
-	sql := ` SELECT * FROM mb_index_main_data WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("gl")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY PUBLISH_TIME DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetEdbDataGlByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_gl WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetEdbDataByGl(edbCode, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND INDEX_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	glDataList, err := GetGlDataByTradeCode(condition, pars)
-	if err != nil {
-		return
-	}
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	dataLen := len(glDataList)
-
-	existMap := make(map[string]string)
-	if dataLen > 0 {
-		var isAdd bool
-		addSql := ` INSERT INTO edb_data_gl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		dataList := make([]*EdbInfoSearchData, 0)
-		for i := 0; i < dataLen; i++ {
-			item := glDataList[i]
-			eDate := item.DataTime
-			sValue := item.InputValue
-			if sValue != "" {
-				if _, ok := existMap[eDate]; !ok {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return nil, err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql("0", edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			}
-			existMap[eDate] = eDate
-		}
-		fmt.Println("isAdd:", isAdd)
-		if isAdd {
-			//addSql = strings.TrimRight(addSql, ",")
-			//fmt.Println("addSql:exec start")
-			//_, err = o.Raw(addSql).Exec()
-			//if err != nil {
-			//	utils.FileLogData.Info("GetEdbDataByGl Err:%s", err.Error())
-			//	return
-			//}
-			//fmt.Println("addSql:exec end")
-			addSql = strings.TrimRight(addSql, ",")
-			utils.FileLog.Info(addSql)
-			err = AddEdbDataGlBySql(addSql)
-			if err != nil {
-				utils.FileLogData.Info("AddEdbDataGlBySql Err:%s", err.Error())
-				return
-			}
-		}
-		dataList, err := GetEdbDataGlByCode(edbCode)
-		if err != nil {
-			utils.FileLogData.Info("GetEdbDataGlByCode Err:%s", err.Error())
-			return searchItem, err
-		}
-		minDate, maxDate, err := GetEdbDataGlMaxOrMinDate(edbCode)
-		if err != nil {
-			return searchItem, err
-		}
-		searchItem.DataList = dataList
-		searchItem.StartDate = minDate
-		searchItem.EndDate = maxDate
-	}
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-func ModifyEdbDataGlStatus(edbInfoId int64, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_gl SET edb_info_id=?, status=1,modify_time=NOW() WHERE edb_code=? `
-	_, err = o.Raw(sql, edbInfoId, edbCode).Exec()
-	return
-}
-
-func GetEdbDataGlByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_gl WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataGl(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_gl SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新钢联指标数据
-func RefreshEdbDataByGl(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND INDEX_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND DATA_DATE>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND DATA_DATE<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetGlDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_gl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		item := v
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataGlByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := item.InputValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataGl(int64(edbInfoId), v.DataTime, v.InputValue)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = v.InputValue
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-//全部刷新隆众数据
-func RefreshAllEdbDataByGl(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND INDEX_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND DATA_DATE>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND DATA_DATE<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetGlDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_gl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		item := v
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := item.InputValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 178
models/data_manage/edb_data_lt.go

@@ -1,178 +0,0 @@
-package data_manage
-
-import (
-	"encoding/json"
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"hongze/hongze_chart_lib/utils"
-	"reflect"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataLt struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-// AddEdbDataLtBySql 执行添加数据的sql
-func AddEdbDataLtBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-// ModifyEdbDataLt 修改路透社数据
-func ModifyEdbDataLt(edbInfoId int64, dataTime string, value float64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_lt SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-func GetEdbDataLtMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_lt WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-func GetEdbDataLtByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_lt WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func GetEdbDataLtByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_lt WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, size).QueryRows(&items)
-	return
-}
-
-//刷新所有数据
-func RefreshAllEdbDataByLt(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	// 获取路透社数据
-	ltDataList, err := QueryEdbDataByLt(edbCode, startDate, endDate)
-	if err != nil {
-		return
-	}
-
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	addSql := ` INSERT INTO edb_data_lt(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	for timestampInt, edbValue := range ltDataList {
-		dataTime := time.Unix(timestampInt/1000, 0)
-
-		//校验数据类型对不对
-		valType := reflect.TypeOf(edbValue)
-		if valType == nil {
-			continue
-		}
-		if valType.String() != "float64" {
-			continue
-		}
-		sValue := edbValue.(float64)
-
-		eDate := dataTime.Format(utils.FormatDate)
-		if err != nil {
-			return err
-		}
-
-		saveValue := utils.SubFloatToString(sValue, 30)
-		if existVal, ok := dataMap[eDate]; !ok {
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-
-			addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-			isAdd = true
-		} else {
-			if existVal != saveValue {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			fmt.Println("RefreshAllEdbDataByLt add Err", err.Error())
-			return
-		}
-	}
-	return
-}
-
-type EdbDataFromLt struct {
-	Close map[int64]interface{} `json:"CLOSE"`
-}
-
-// QueryEdbDataByLt 获取路透社数据
-func QueryEdbDataByLt(edbCode, startDate, endDate string) (dataList map[int64]interface{}, err error) {
-	dataList = make(map[int64]interface{})
-
-	ltUrl := utils.Hz_Data_LT_Url + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s`
-	ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate)
-	utils.FileLogData.Info("ltUrl:%s", ltUrl)
-	body, err := http.Get(ltUrl)
-	utils.FileLogData.Info("lt result:%s", string(body))
-
-	if err != nil {
-		return
-	}
-	//fmt.Println(string(body))
-	item := new(EdbDataFromLt)
-	err = json.Unmarshal(body, &item)
-
-	if err != nil {
-		return
-	}
-	dataList = item.Close
-	return
-}

+ 0 - 329
models/data_manage/edb_data_lz.go

@@ -1,329 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-func AddEdbDataLzBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataLzByEdbCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_lz WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetEdbDataLzMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_lz WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-type lzSurveyData struct {
-	DataTime   string `orm:"column(data_time)" description:"日期"`
-	InputValue string `orm:"column(input_value)" description:"值"`
-}
-
-func GetLzSurveyDataByTradeCode(condition string, pars []interface{}) (item []*lzSurveyData, err error) {
-	sql := ` SELECT  a.* FROM longzhong_survey_data AS a
-				INNER JOIN longzhong_survey_product AS b ON a.survey_product_id=b.survey_product_id
-				WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("edb")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY a.data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetEdbDataLzByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_lz WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetEdbDataByLz(edbCode, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND b.lz_code=? "
-		pars = append(pars, edbCode)
-	}
-
-	lzDataList, err := GetLzSurveyDataByTradeCode(condition, pars)
-	if err != nil {
-		return
-	}
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	dataLen := len(lzDataList)
-
-	if dataLen > 0 {
-		var isAdd bool
-		addSql := ` INSERT INTO edb_data_lz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		dataList := make([]*EdbInfoSearchData, 0)
-		for i := 0; i < dataLen; i++ {
-			item := lzDataList[i]
-			eDate := item.DataTime
-			sValue := item.InputValue
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return nil, err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += "("
-			addSql += "0," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + sValue + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "0" + "," + "'" + timeStr + "'"
-			addSql += "),"
-			isAdd = true
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			err = AddEdbDataLzBySql(addSql)
-			if err != nil {
-				utils.FileLogData.Info("AddEdbDataLzBySql Err:%s", err.Error())
-				return
-			}
-		}
-
-		dataList, err := GetEdbDataLzByCode(edbCode)
-		if err != nil {
-			utils.FileLogData.Info("GetEdbDataLzByCode Err:%s", err.Error())
-			return searchItem, err
-		}
-		minDate, maxDate, err := GetEdbDataLzMaxOrMinDate(edbCode)
-		if err != nil {
-			return searchItem, err
-		}
-		searchItem.DataList = dataList
-		searchItem.StartDate = minDate
-		searchItem.EndDate = maxDate
-	}
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-func ModifyEdbDataLzStatus(edbInfoId int64, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_lz SET edb_info_id=?, status=1,modify_time=NOW() WHERE edb_code=? `
-	_, err = o.Raw(sql, edbInfoId, edbCode).Exec()
-	return
-}
-
-func GetEdbDataLzByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_lz WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataLz(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_lz SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新隆众指标数据
-func RefreshEdbDataByLz(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND b.lz_code=? "
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND a.data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND a.data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	lzDataList, err := GetLzSurveyDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_lz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for _, v := range lzDataList {
-		item := v
-		count, err := GetEdbDataLzByCodeAndDate(edbCode, v.DataTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return err
-		}
-		if count <= 0 {
-			nowStr := time.Now().Format(utils.FormatDateTime)
-			eDate := item.DataTime
-			sValue := item.InputValue
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += "("
-			addSql += edbInfoIdStr + "," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + sValue + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "1" + "," + "'" + timeStr + "'"
-			addSql += "),"
-			isAdd = true
-		} else {
-			err = ModifyEdbDataLz(int64(edbInfoId), v.DataTime, v.InputValue)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-//全部刷新隆众数据
-func RefreshAllEdbDataByLz(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND b.lz_code=? "
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND a.data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND a.data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	lzDataList, err := GetLzSurveyDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_lz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for _, v := range lzDataList {
-		item := v
-
-		eDate := item.DataTime
-		sValue := item.InputValue
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			return err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		saveValue := sValue
-
-		if existVal, ok := dataMap[eDate]; !ok {
-			addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-			isAdd = true
-		} else {
-			if existVal != saveValue {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 321
models/data_manage/edb_data_manual.go

@@ -1,321 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-func AddEdbDataManualBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataManualMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_manual WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-type ManualEdbdata struct {
-	TradeCode  string    `orm:"column(TRADE_CODE);pk" description:"指标编码"`
-	Dt         string    `orm:"column(DT)" description:"日期"`
-	Close      string    `orm:"column(CLOSE)" description:"值"`
-	ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
-}
-
-func GetEdbdataManualByTradeCode(condition string, pars []interface{}) (item []*ManualEdbdata, err error) {
-	sql := ` SELECT  * FROM edbdata WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("edb")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY DT DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetEdbDataManualByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_manual WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, size).QueryRows(&items)
-	return
-}
-
-func GetEdbDataByManual(edbCode, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND TRADE_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	manualDataList, err := GetEdbdataManualByTradeCode(condition, pars)
-	if err != nil {
-		return
-	}
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	dataLen := len(manualDataList)
-
-	if dataLen > 0 {
-		var isAdd bool
-		addSql := ` INSERT INTO edb_data_manual(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		dataList := make([]*EdbInfoSearchData, 0)
-		for i := 0; i < dataLen; i++ {
-			item := manualDataList[i]
-			eDate := item.Dt
-			sValue := item.Close
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return nil, err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += "("
-			addSql += "0," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + sValue + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "0" + "," + "'" + timeStr + "'"
-			addSql += "),"
-			isAdd = true
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			err = AddEdbDataManualBySql(addSql)
-			if err != nil {
-				utils.FileLogData.Info("AddEdbDataThsBySql Err:%s", err.Error())
-				return
-			}
-		}
-
-		size := utils.EDB_DATA_LIMIT
-		dataList, err := GetEdbDataManualByCode(edbCode, size)
-		if err != nil {
-			utils.FileLogData.Info("GetEdbDataThsByCode Err:%s", err.Error())
-			return searchItem, err
-		}
-		minDate, maxDate, err := GetEdbDataManualMaxOrMinDate(edbCode)
-		if err != nil {
-			return searchItem, err
-		}
-		searchItem.DataList = dataList
-		searchItem.StartDate = minDate
-		searchItem.EndDate = maxDate
-	}
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-func GetEdbDataManualByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_manual WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataManual(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_manual SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新手工指标数据
-func RefreshEdbDataByManual(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND TRADE_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND DT>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND DT<=? "
-		pars = append(pars, endDate)
-	}
-
-	manualDataList, err := GetEdbdataManualByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_manual(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for _, v := range manualDataList {
-		item := v
-		count, err := GetEdbDataManualByCodeAndDate(v.TradeCode, v.Dt)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return err
-		}
-		if count <= 0 {
-			nowStr := time.Now().Format(utils.FormatDateTime)
-			eDate := item.Dt
-			sValue := item.Close
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += "("
-			addSql += edbInfoIdStr + "," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + sValue + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "1" + "," + "'" + timeStr + "'"
-			addSql += "),"
-			isAdd = true
-		} else {
-			err = ModifyEdbDataManual(int64(edbInfoId), v.Dt, v.Close)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-//刷新手工指标数据
-func RefreshAllEdbDataByManual(edbInfoId, source int, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		condition += " AND TRADE_CODE=? "
-		pars = append(pars, edbCode)
-	}
-
-	manualDataList, err := GetEdbdataManualByTradeCode(condition, pars)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]*EdbDataBase)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_manual(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	manualMap := make(map[string]*ManualEdbdata)
-	for _, v := range manualDataList {
-		item := v
-		if findItem, ok := existDataMap[v.Dt]; !ok {
-			eDate := item.Dt
-			sValue := item.Close
-
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-
-			addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-			isAdd = true
-		} else {
-			if findItem.Value != item.Close {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, item.Close, edbInfoId, item.Dt).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-		manualMap[v.Dt] = v
-	}
-	for _, v := range existDataList {
-		if _, ok := manualMap[v.DataTime]; !ok {
-			go DeleteEdbDataByIdAndSource(v.EdbDataId, utils.DATA_SOURCE_MANUAL)
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			fmt.Println("RefreshAllEdbDataByManual add Err", err.Error())
-			return
-		}
-	}
-	return
-}
-
-func DeleteEdbDataByIdAndSource(edbDataId, source int) (err error) {
-	sql := ` DELETE FROM %s WHERE edb_data_id=? `
-	tableName := GetEdbDataTableName(source)
-	sql = fmt.Sprintf(sql, tableName)
-
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sql, edbDataId).Exec()
-	return
-}

+ 0 - 171
models/data_manage/edb_data_pb.go

@@ -1,171 +0,0 @@
-package data_manage
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"net/url"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataPb struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	Ticker        string
-	Field         string
-	DataTimestamp int64
-}
-
-func AddEdbDataPb(items []*EdbDataPb) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func AddEdbDataPbBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func ModifyEdbDataPb(edbInfoId int, dataTime string, value float64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_pb SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-func GetEdbDataPbMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_pb WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-func GetEdbDataPbByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_pb WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, size).QueryRows(&items)
-	return
-}
-
-func GetEdbDataPbByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_pb WHERE edb_code=? AND data_time>=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-type EdbDataFromPb struct {
-	Date   map[string]int64   `json:"date"`
-	Ticker map[string]string  `json:"ticker"`
-	Field  map[string]string  `json:"field"`
-	Value  map[string]float64 `json:"value"`
-}
-
-//全部刷新
-func RefreshAllEdbDataByPb(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	refreshEdbCode := edbCode
-	edbCode = url.QueryEscape(edbCode)
-	bpUrl := utils.Hz_Data_PB_Url + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
-	bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", bpUrl)
-	body, err := http.Get(bpUrl)
-	fmt.Println("RefreshAllEdbDataByPb body:")
-	fmt.Println(string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromPb)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	if len(item.Date) > 0 {
-		dateMap := item.Date
-		var isAdd bool
-		addSql := ` INSERT INTO edb_data_pb(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,ticker,field,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		for k, v := range dateMap {
-			timeStr := fmt.Sprintf("%d", v)
-			v = v / 1000
-			t := time.Unix(v, 0)
-			dateTime := t.Format(utils.FormatDate)
-			val := item.Value[k]
-			field := item.Field[k]
-			ticker := item.Ticker[k]
-			saveValue := utils.SubFloatToString(val, 30)
-			if field == "PX_LAST" {
-				if existVal, ok := dataMap[dateTime]; !ok {
-					addSql += "("
-					addSql += edbInfoIdStr + "," + "'" + refreshEdbCode + "'" + "," + "'" + dateTime + "'" + "," + saveValue + "," + "'" + nowStr + "'" +
-						"," + "'" + nowStr + "'" + "," + "1" + "," + "'" + ticker + "'" + "," + "'" + field + "'" + "," + "'" + timeStr + "'"
-					addSql += "),"
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, saveValue, edbInfoId, dateTime).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				fmt.Println("RefreshAllEdbDataByPb add Err", err.Error())
-				return
-			}
-		}
-	}
-	return
-}

+ 0 - 727
models/data_manage/edb_data_quarter.go

@@ -1,727 +0,0 @@
-package data_manage
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"sort"
-	"strconv"
-	"strings"
-	"time"
-
-	"github.com/nosixtools/solarlunar"
-)
-
-func GetEdbDataQuarterCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	hsql := `SELECT COUNT(1) AS count FROM edb_data_quarter WHERE edb_info_id=? `
-	err = o.Raw(hsql, edbInfoId).QueryRow(&count)
-	return
-}
-
-//指标季度数据计算
-func AddCalculateQuarter(edbInfoId, source int, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("Err:", err)
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println(edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfoId)
-	dataList, err := GetEdbDataListAll(condition, pars, source, 0)
-	if err != nil {
-		return err
-	}
-
-	var yearArr []int
-	yearMap := make(map[int]int)
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		//日其中获取年
-		itemDate, err := time.Parse(utils.FormatDate, v.DataTime)
-		if err != nil {
-			return err
-		}
-		year := itemDate.Year()
-		if _, ok := yearMap[year]; !ok {
-			yearArr = append(yearArr, year)
-			yearMap[year] = year
-		}
-		dataMap[v.DataTime] = v
-	}
-	sort.Sort(sort.Reverse(sort.IntSlice(yearArr)))
-	addSql := ` INSERT INTO edb_data_quarter(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	//yearLen := len(yearArr)
-
-	fmt.Println(yearArr)
-
-	for _, yv := range yearArr {
-		currentYear := yv
-		hsql := `SELECT * FROM holiday WHERE year=? `
-		currentHolidayObj := new(Holiday)
-		err = o.Raw(hsql, currentYear).QueryRow(&currentHolidayObj)
-		if err != nil {
-			fmt.Println("get holiday err:" + err.Error())
-			return err
-		}
-		cjDate := currentHolidayObj.HolidayDate
-		fmt.Println("year:", yv, "cjDate:", cjDate)
-		//utils.FileLog.Info("cjDate:", cjDate)
-		existMap := make(map[string]string)
-
-		for i := 1; i <= 70; i++ {
-			preDate := cjDate.Format(utils.FormatDate)
-			fmt.Println("year:", yv, "preDate:", preDate, "i:", i)
-			if findItem, ok := dataMap[preDate]; ok {
-				timestamp := currentHolidayObj.HolidayDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				if _, exist := existMap[preDate]; !exist {
-					valStr := utils.SubFloatToString(findItem.Value, 4)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, preDate, timestampStr, valStr)
-					isAdd = true
-				}
-			}
-			cjDate = cjDate.AddDate(0, 0, -1)
-		}
-		cjDate = currentHolidayObj.HolidayDate
-		for i := 1; i <= 70; i++ {
-			nextDate := cjDate.Format(utils.FormatDate)
-			fmt.Println("year:", yv, "nextDate:", nextDate, "i:", i)
-			if findItem, ok := dataMap[nextDate]; ok {
-				timestamp := currentHolidayObj.HolidayDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				if _, exist := existMap[nextDate]; !exist {
-					valStr := utils.SubFloatToString(findItem.Value, 4)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, nextDate, timestampStr, valStr)
-					isAdd = true
-				}
-			}
-			cjDate = cjDate.AddDate(0, 0, +1)
-		}
-
-		//nextIndex := yk + 1
-		//if nextIndex < yearLen {
-		//	nextYear := yearArr[nextIndex]
-		//	fmt.Println("year:", currentYear, nextYear)
-		//	nextHolidayObj := new(Holiday)
-		//	hsql := `SELECT * FROM holiday WHERE year=? `
-		//	err = o.Raw(hsql, nextYear).QueryRow(&nextHolidayObj)
-		//	if err != nil {
-		//		return err
-		//	}
-		//	nextHolidayStr := nextHolidayObj.HolidayDate.Format(utils.FormatDate)
-		//	currentHolidayStr := currentHolidayObj.HolidayDate.Format(utils.FormatDate)
-		//
-		//	if findItem, ok := dataMap[nextHolidayStr]; ok {
-		//		timestamp := currentHolidayObj.HolidayDate.UnixNano() / 1e6
-		//		timestampStr := fmt.Sprintf("%d", timestamp)
-		//		addSql += GetAddSql(edbInfoIdStr, edbCode, currentHolidayStr, timestampStr, findItem.Value)
-		//		isAdd = true
-		//	}
-		//
-		//	nextMinDate := strconv.Itoa(nextYear) + "-01-01"
-		//	nextMaxDate := strconv.Itoa(nextYear) + "-12-31"
-		//	currentMinDate := strconv.Itoa(currentYear) + "-01-01"
-		//	currentMaxDate := strconv.Itoa(currentYear) + "-12-31"
-		//
-		//	i := 0
-		//	for {
-		//		i--
-		//		nextHolidayFormat := nextHolidayObj.HolidayDate.AddDate(0, 0, i)
-		//		currentHolidayFormat := currentHolidayObj.HolidayDate.AddDate(0, 0, i)
-		//
-		//		nextHolidayStr := nextHolidayFormat.Format(utils.FormatDate)
-		//		currentHolidayStr := currentHolidayFormat.Format(utils.FormatDate)
-		//
-		//		fmt.Println("currentHolidayStr:", currentHolidayStr, nextHolidayStr)
-		//		if findItem, ok := dataMap[nextHolidayStr]; ok {
-		//			timestamp := currentHolidayFormat.UnixNano() / 1e6
-		//			timestampStr := fmt.Sprintf("%d", timestamp)
-		//			addSql += GetAddSql(edbInfoIdStr, edbCode, currentHolidayStr, timestampStr, findItem.Value)
-		//			isAdd = true
-		//		}
-		//		//fmt.Println("nextHolidayStr:", nextHolidayStr,nextMinDate)
-		//		if nextHolidayStr == nextMinDate || currentHolidayStr == currentMinDate {
-		//			fmt.Println("min跳出循环:" + nextMinDate)
-		//			break
-		//		}
-		//	}
-		//
-		//	n := 0
-		//	for {
-		//		n++
-		//		nextHolidayFormat := nextHolidayObj.HolidayDate.AddDate(0, 0, n)
-		//		currentHolidayFormat := currentHolidayObj.HolidayDate.AddDate(0, 0, n)
-		//
-		//		nextHolidayStr := nextHolidayFormat.Format(utils.FormatDate)
-		//		currentHolidayStr := currentHolidayFormat.Format(utils.FormatDate)
-		//
-		//		fmt.Println("currentHolidayStr:", currentHolidayStr, nextHolidayStr)
-		//
-		//		if findItem, ok := dataMap[nextHolidayStr]; ok {
-		//			timestamp := currentHolidayFormat.UnixNano() / 1e6
-		//			timestampStr := fmt.Sprintf("%d", timestamp)
-		//
-		//			addSql += GetAddSql(edbInfoIdStr, edbCode, currentHolidayStr, timestampStr, findItem.Value)
-		//			isAdd = true
-		//		}
-		//
-		//		//fmt.Println("nextHolidayStr:", nextHolidayStr,nextMaxDate)
-		//		if nextHolidayStr == nextMaxDate || currentHolidayStr == currentMaxDate {
-		//			fmt.Println("max跳出循环:" + nextMaxDate)
-		//			break
-		//		}
-		//	}
-		//}
-	}
-	fmt.Println("isAdd", isAdd)
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info(addSql)
-		_, err = o.Raw(addSql).Exec()
-		fmt.Println("err:", err)
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-//指标季度数据计算(公历转农历)
-func AddCalculateQuarterV2(edbInfoId, source int, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("Err:", err)
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println(edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfoId)
-	dataList, err := GetEdbDataListAll(condition, pars, source, 0)
-	if err != nil {
-		return err
-	}
-
-	var yearArr []int
-	yearMap := make(map[int]int)
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		//日其中获取年
-		itemDate, err := time.Parse(utils.FormatDate, v.DataTime)
-		if err != nil {
-			return err
-		}
-		year := itemDate.Year()
-		if _, ok := yearMap[year]; !ok {
-			yearArr = append(yearArr, year)
-			yearMap[year] = year
-		}
-		dataMap[v.DataTime] = v
-	}
-	sort.Sort(sort.Reverse(sort.IntSlice(yearArr)))
-	addSql := ` INSERT INTO edb_data_quarter(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	//yearLen := len(yearArr)
-
-	fmt.Println(yearArr)
-
-	for _, yv := range yearArr {
-		fmt.Println(yv)
-	}
-	fmt.Println("isAdd", isAdd)
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info(addSql)
-		_, err = o.Raw(addSql).Exec()
-		fmt.Println("err:", err)
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-//指标季度数据计算(公历转农历)
-func AddCalculateQuarterV3(edbInfoId, source int, edbCode string, list []*EdbDataList) (err error) {
-	var errMsg string
-	defer func() {
-		if errMsg != "" {
-			fmt.Println("errMsg:", errMsg)
-		}
-	}()
-	lunarDate := "2017-01-01" //农历
-	fmt.Println(solarlunar.LunarToSolar(lunarDate, false))
-
-	dataList, err := GetHzTestEdbdata()
-	var yearArr []int
-	yearMap := make(map[int]int)
-	var cureentDate time.Time
-	for k, v := range dataList {
-		if k == 0 {
-			cureentDate = v.Dt
-		}
-		year := v.Dt.Year()
-		if _, ok := yearMap[year]; !ok {
-			yearArr = append(yearArr, year)
-		}
-		yearMap[year] = year
-	}
-	//排序
-	fmt.Println(yearArr)
-	thisYear := cureentDate.Year()
-	thisMonth := int(cureentDate.Month())
-
-	sort.Ints(yearArr)
-	fmt.Println("thisYear:", thisYear)
-
-	result := new(HzTestEdbdataResult)
-	for ky, vy := range yearArr {
-		if thisMonth < 11 {
-			currentYearCjnl := strconv.Itoa(thisYear) + "-01-01"               //当前年份春节农历
-			currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
-			currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return err
-			}
-
-			fmt.Println(ky, vy)
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return err
-			}
-			day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-			fmt.Println("day:", day)
-			items := new(HzTestEdbdataItems)
-			dataLen := len(dataList)
-			for i := dataLen - 1; i >= 0; i-- {
-				v := dataList[i]
-				newDate := v.Dt.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-
-				if newDate.Before(selectDate) {
-					item := new(HzTestEdbdata)
-					item.TtradeCode = v.TtradeCode
-					item.Dt = newDate
-					item.Close = v.Close
-					timestamp := item.Dt.UnixNano() / 1e6
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			result.List = append(result.List, items)
-		} else {
-			fmt.Println(ky, vy)
-			nextYear := thisYear + 1
-			nextYearCjnl := strconv.Itoa(nextYear) + "-01-01"            //当前年份春节农历
-			nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
-
-			nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return err
-			}
-
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return err
-			}
-			day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-
-			fmt.Println("day:", day)
-			items := new(HzTestEdbdataItems)
-			dataLen := len(dataList)
-			for i := dataLen - 1; i >= 0; i-- {
-				v := dataList[i]
-				newDate := v.Dt.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-
-				if newDate.Before(selectDate) {
-					item := new(HzTestEdbdata)
-					item.TtradeCode = v.TtradeCode
-					item.Dt = newDate
-					item.Close = v.Close
-					timestamp := item.Dt.UnixNano() / 1e6
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			result.List = append(result.List, items)
-		}
-
-	}
-	resultJson, err := json.Marshal(result)
-	utils.FileLog.Info(string(resultJson))
-	return
-}
-
-//指标季度数据计算(公历转农历)
-func AddCalculateQuarterV4(dataList []*EdbDataList) (result *EdbDataResult, err error) {
-	var errMsg string
-	defer func() {
-		if errMsg != "" {
-			fmt.Println("errMsg:", errMsg)
-		}
-	}()
-
-	endDate := dataList[len(dataList)-1].DataTime
-	endDateForm, err := time.Parse(utils.FormatDate, endDate)
-	if err != nil {
-		return result, err
-	}
-	thisMonth := int(endDateForm.Month())
-
-	result = new(EdbDataResult)
-	var yearArr []int
-	yearMap := make(map[int]int)
-	var cureentDate time.Time
-	if thisMonth < 11 {
-		for k, v := range dataList {
-			dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-			if err != nil {
-				errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-				return result, err
-			}
-			if k == len(dataList)-1 {
-				cureentDate = dateTime
-			}
-			year := dateTime.Year()
-			if _, ok := yearMap[year]; !ok {
-				yearArr = append(yearArr, year)
-			}
-			yearMap[year] = year
-		}
-	} else {
-		for k, v := range dataList {
-			dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-			if err != nil {
-				errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-				return result, err
-			}
-			if k == len(dataList)-1 {
-				cureentDate = dateTime
-			}
-			year := dateTime.Year() + 1
-			if _, ok := yearMap[year]; !ok {
-				yearArr = append(yearArr, year)
-			}
-			yearMap[year] = year
-		}
-	}
-	//排序
-	fmt.Println("yearArr:", yearArr)
-	thisYear := cureentDate.Year()
-	//thisMonth := int(cureentDate.Month())
-
-	fmt.Println("thisMonth:", thisMonth)
-	for ky, vy := range yearArr {
-		fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
-		if thisMonth < 11 {
-			currentYearCjnl := strconv.Itoa(thisYear) + "-01-01"               //当前年份春节农历
-			currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
-			currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-
-			items := new(EdbDataItems)
-			items.Year = preYear
-			for _, v := range dataList {
-				dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-				if err != nil {
-					errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-					return result, err
-				}
-				newDate := dateTime.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-				if newDate.Before(selectDate) || newDate == selectDate {
-					timestamp := newDate.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = newDate.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			result.List = append(result.List, items)
-		} else {
-			nextYear := thisYear + 1
-			nextYearCjnl := strconv.Itoa(nextYear) + "-01-01"            //当前年份春节农历
-			nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
-
-			nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-			preYear := vy
-			preYearCjnl := strconv.Itoa(preYear) + "-01-01"            //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-
-			fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
-
-			items := new(EdbDataItems)
-			items.Year = preYear - 1
-			fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
-			if ky+1 < len(yearArr) {
-				for _, v := range dataList {
-					dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-					if err != nil {
-						errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-						return result, err
-					}
-					newDate := dateTime.AddDate(0, 0, int(day))
-					selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
-					selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-
-					if newDate.Before(selectDate) || newDate == selectDate {
-						timestamp := newDate.UnixNano() / 1e6
-						item := new(EdbDataList)
-						item.DataTime = newDate.Format(utils.FormatDate)
-						item.EdbInfoId = v.EdbInfoId
-						item.Value = v.Value
-						item.EdbDataId = v.EdbDataId
-						item.DataTimestamp = timestamp
-						items.Items = append(items.Items, item)
-					}
-				}
-				result.List = append(result.List, items)
-			} else {
-				for _, v := range dataList {
-					dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
-					if err != nil {
-						errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
-						return result, err
-					}
-					timestamp := dateTime.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = dateTime.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-				result.List = append(result.List, items)
-			}
-		}
-	}
-	return
-}
-
-type HzTestEdbdataResult struct {
-	List []*HzTestEdbdataItems
-}
-
-type HzTestEdbdataItems struct {
-	Items []*HzTestEdbdata
-}
-
-type HzTestEdbdata struct {
-	TtradeCode    string    `orm:"column(TRADE_CODE)"`
-	Dt            time.Time `orm:"column(DT)"`
-	Close         float64   `orm:"column(CLOSE)"`
-	ModifyTime    time.Time `orm:"column(modify_time)"`
-	DataTimestamp int64
-}
-
-func GetHzTestEdbdata() (list []*HzTestEdbdata, err error) {
-	o := orm.NewOrm()
-	sql := ` SELECT * FROM hz_test_edbdata WHERE TRADE_CODE=? ORDER BY DT DESC `
-	_, err = o.Raw(sql, "ST_0000577845").QueryRows(&list)
-	return
-}
-
-type EdbDataItems struct {
-	Items []*EdbDataList
-	Year  int
-}
-
-type EdbDataResult struct {
-	List []*EdbDataItems
-}
-
-func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
-	var errMsg string
-	defer func() {
-		if errMsg != "" {
-			fmt.Println("errMsg:", errMsg)
-		}
-	}()
-	result = new(EdbDataResult)
-	thisYear := time.Now().Year()
-
-	endDate := dataList[len(dataList)-1].DataTime
-	endDateForm, err := time.Parse(utils.FormatDate, endDate)
-	if err != nil {
-		return result, err
-	}
-	thisMonth := int(endDateForm.Month())
-
-	fmt.Println(thisMonth)
-	for i := 4; i > 0; i-- {
-		if thisMonth < 11 {
-			nextYear := thisYear
-			nextYearCjnl := strconv.Itoa(nextYear) + "-01-01"            //当前年份春节农历
-			nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
-			nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-			preYearCjnl := strconv.Itoa(nextYear-i) + "-01-01"         //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-			items := new(EdbDataItems)
-			for _, v := range dataList {
-				dataDate := v.DataTime
-				dataDateForm, err := time.Parse(utils.FormatDate, dataDate)
-				if err != nil {
-					return result, err
-				}
-				newDate := dataDateForm.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(nextYear) + "-11" + "-30"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-				if newDate.Before(selectDate) {
-					timestamp := newDate.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = newDate.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			fmt.Println(nextYear, "年春节阳历", nextYearCjgl)
-			fmt.Println(i, "年前春节", preYearCjnl)
-			fmt.Println(i, "年前春节阳历", preYearCjgl)
-			fmt.Println("与", nextYear, "年春节相差天数", day, "____________")
-			result.List = append(result.List, items)
-		} else {
-			nextYear := thisYear + 1
-			nextYearCjnl := strconv.Itoa(nextYear) + "-01-01"            //当前年份春节农历
-			nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
-			nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
-			if err != nil {
-				errMsg = "生成当前春节失败,Err:" + err.Error()
-				return result, err
-			}
-			preYearCjnl := strconv.Itoa(nextYear-i) + "-01-01"         //之前年份春节农历
-			preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
-			preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
-			if err != nil {
-				errMsg = "生成历史年份春节失败,Err:" + err.Error()
-				return result, err
-			}
-			day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
-			items := new(EdbDataItems)
-			for _, v := range dataList {
-				dataDate := v.DataTime
-				dataDateForm, err := time.Parse(utils.FormatDate, dataDate)
-				if err != nil {
-					return result, err
-				}
-
-				newDate := dataDateForm.AddDate(0, 0, int(day))
-				selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
-				selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
-				if newDate.Before(selectDate) {
-					timestamp := newDate.UnixNano() / 1e6
-					item := new(EdbDataList)
-					item.DataTime = newDate.Format(utils.FormatDate)
-					item.EdbInfoId = v.EdbInfoId
-					item.Value = v.Value
-					item.EdbDataId = v.EdbDataId
-					item.DataTimestamp = timestamp
-					items.Items = append(items.Items, item)
-				}
-			}
-			fmt.Println(nextYear, "年春节阳历", nextYearCjgl)
-			fmt.Println(i, "年前春节", preYearCjnl)
-			fmt.Println(i, "年前春节阳历", preYearCjgl)
-			fmt.Println("与", nextYear, "年春节相差天数", day, "____________")
-			result.List = append(result.List, items)
-		}
-	}
-	//合并第五组数据
-	items := new(EdbDataItems)
-	for _, v := range dataList {
-		dataDate := v.DataTime
-		dataDateForm, err := time.Parse(utils.FormatDate, dataDate)
-		if err != nil {
-			return result, err
-		}
-		timestamp := dataDateForm.UnixNano() / 1e6
-		item := new(EdbDataList)
-		item.DataTime = v.DataTime
-		item.EdbInfoId = v.EdbInfoId
-		item.Value = v.Value
-		item.EdbDataId = v.EdbDataId
-		item.DataTimestamp = timestamp
-		items.Items = append(items.Items, item)
-	}
-	result.List = append(result.List, items)
-	return
-}

+ 0 - 423
models/data_manage/edb_data_sh.go

@@ -1,423 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type ShData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-type BaseFromShDataSimple struct {
-	Id        int `orm:"column(base_from_trade_shanghai_index_id);pk"`
-	DealCode  string
-	BuyCode   string
-	SoldCode  string
-	DataTime  string
-	DealValue string
-	BuyValue  string
-	SoldValue string
-}
-
-type BaseInfoFromSh struct {
-	DealName string
-	BuyName  string
-	SoldName string
-}
-
-type BaseFromTradeShIndex struct {
-	BaseFromTradeShIndexId int `orm:"column(base_from_trade_shanghai_index_id);pk"`
-	Rank                   int
-	DealShortName          string
-	DealName               string
-	DealCode               string
-	DealValue              string
-	DealChange             int
-	BuyShortName           string
-	BuyName                string
-	BuyCode                string
-	BuyValue               string
-	BuyChange              int
-	SoldShortName          string
-	SoldName               string
-	SoldCode               string
-	SoldValue              string
-	SoldChange             int
-	Frequency              string
-	ClassifyName           string
-	ClassifyType           string
-	CreateTime             time.Time
-	ModifyTime             time.Time
-	DataTime               string
-}
-
-func GetEdbDataShMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_sh WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
-	return
-}
-
-func GetEdbDataBySh(edbCode, suffix, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	shBaseDataAll, err := GetBaseFromShDataAllByIndexCode(edbCode, suffix)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_sh(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range shBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			if suffix == "deal" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
-			} else if suffix == "buy" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
-			} else {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
-			}
-			isAdd = true
-		}
-		if suffix == "deal" {
-			existMap[eDate] = sv.DealValue
-		} else if suffix == "buy" {
-			existMap[eDate] = sv.BuyValue
-		} else {
-			existMap[eDate] = sv.SoldValue
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_SH, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataShByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataShMaxOrMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-// RefreshEdbDataBySh 刷新上期所指标数据
-func RefreshEdbDataBySh(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetShDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_sh(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataShByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := itemValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataSh(int64(edbInfoId), v.DataTime, value)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// RefreshAllEdbDataBySh 全部刷新上期所
-func RefreshAllEdbDataBySh(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetShDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_sh(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := itemValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// GetBaseInfoFromShByIndexCode 获取指标信息
-func GetBaseInfoFromShByIndexCode(indexCode, suffix string) (list []*BaseInfoFromSh, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_shanghai_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetShDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromShDataSimple, err error) {
-	sql := ` SELECT * FROM base_from_trade_shanghai_index WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("data")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func AddEdbDataShBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataShByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_sh WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetBaseFromShDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeShIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_shanghai_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetEdbDataShByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_sh WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataSh(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_sh SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}

+ 0 - 423
models/data_manage/edb_data_shfe.go

@@ -1,423 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type ShfeData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-type BaseFromShfeDataSimple struct {
-	Id        int `orm:"column(base_from_trade_ine_index_id);pk"`
-	DealCode  string
-	BuyCode   string
-	SoldCode  string
-	DataTime  string
-	DealValue string
-	BuyValue  string
-	SoldValue string
-}
-
-type BaseInfoFromShfe struct {
-	DealName string
-	BuyName  string
-	SoldName string
-}
-
-type BaseFromTradeShfeIndex struct {
-	BaseFromTradeShfeIndexId int `orm:"column(base_from_trade_ine_index_id);pk"`
-	Rank                     int
-	DealShortName            string
-	DealName                 string
-	DealCode                 string
-	DealValue                string
-	DealChange               int
-	BuyShortName             string
-	BuyName                  string
-	BuyCode                  string
-	BuyValue                 string
-	BuyChange                int
-	SoldShortName            string
-	SoldName                 string
-	SoldCode                 string
-	SoldValue                string
-	SoldChange               int
-	Frequency                string
-	ClassifyName             string
-	ClassifyType             string
-	CreateTime               time.Time
-	ModifyTime               time.Time
-	DataTime                 string
-}
-
-func GetEdbDataShfeMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_ine WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
-	return
-}
-
-func GetEdbDataByShfe(edbCode, suffix, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	ineBaseDataAll, err := GetBaseFromShfeDataAllByIndexCode(edbCode, suffix)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range ineBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			if suffix == "deal" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
-			} else if suffix == "buy" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
-			} else {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
-			}
-			isAdd = true
-		}
-		if suffix == "deal" {
-			existMap[eDate] = sv.DealValue
-		} else if suffix == "buy" {
-			existMap[eDate] = sv.BuyValue
-		} else {
-			existMap[eDate] = sv.SoldValue
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_SHFE, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataShfeByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataShfeMaxOrMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-// RefreshEdbDataByShfe 刷新上期能源指标数据
-func RefreshEdbDataByShfe(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetShfeDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataShfeByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := itemValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataShfe(int64(edbInfoId), v.DataTime, value)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// RefreshAllEdbDataByShfe 全部刷新上期能源
-func RefreshAllEdbDataByShfe(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetShfeDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := itemValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// GetBaseInfoFromShfeByIndexCode 获取指标信息
-func GetBaseInfoFromShfeByIndexCode(indexCode, suffix string) (list []*BaseInfoFromShfe, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_ine_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetShfeDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromShfeDataSimple, err error) {
-	sql := ` SELECT * FROM base_from_trade_ine_index WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("data")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func AddEdbDataShfeBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataShfeByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_ine WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetBaseFromShfeDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeShfeIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_ine_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetEdbDataShfeByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_ine WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataShfe(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_ine SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}

+ 0 - 165
models/data_manage/edb_data_ths.go

@@ -1,165 +0,0 @@
-package data_manage
-
-import (
-	"encoding/json"
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataThs struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-func AddEdbDataThsBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func ModifyEdbDataThs(edbInfoId int64, dataTime string, value float64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_ths SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-func GetEdbDataThsMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ths WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-func GetEdbDataThsByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_ths WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func GetEdbDataThsByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_ths WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, size).QueryRows(&items)
-	return
-}
-
-type EdbDataFromThs struct {
-	DataVol   int64       `json:"dataVol"`
-	Errmsg    string      `json:"errmsg"`
-	Errorcode int64       `json:"errorcode"`
-	Perf      interface{} `json:"perf"`
-	Tables    []struct {
-		ID    []string  `json:"id"`
-		Time  []string  `json:"time"`
-		Value []float64 `json:"value"`
-	} `json:"tables"`
-}
-
-//刷新所有数据
-func RefreshAllEdbDataByThs(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	thsUrl := utils.Hz_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	fmt.Println("GetEdbDataByThs body:")
-	fmt.Println(string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromThs)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	if item.Errorcode != 0 {
-		err = errors.New(string(body))
-		return
-	}
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	if len(item.Tables) > 0 {
-		table := item.Tables[0]
-		dataLen := len(table.Time)
-		addSql := ` INSERT INTO edb_data_ths(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		for i := 0; i < dataLen; i++ {
-			eDate := table.Time[i]
-			sValue := table.Value[i]
-			saveValue := utils.SubFloatToString(sValue, 30)
-			if existVal, ok := dataMap[eDate]; !ok {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-
-				addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-				isAdd = true
-			} else {
-				if existVal != saveValue {
-					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-					sql = fmt.Sprintf(sql, dataTableName)
-					_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				fmt.Println("RefreshAllEdbDataByThs add Err", err.Error())
-				return
-			}
-		}
-	}
-	return
-}

+ 0 - 166
models/data_manage/edb_data_wind.go

@@ -1,166 +0,0 @@
-package data_manage
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataWind struct {
-	EdbDataId     int `orm:"column(edb_data_id);pk"`
-	EdbInfoId     int
-	EdbCode       string
-	DataTime      string
-	Value         float64
-	Status        int
-	CreateTime    time.Time
-	ModifyTime    time.Time
-	DataTimestamp int64
-}
-
-func AddEdbDataWind(items []*EdbDataWind) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func AddEdbDataWindBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func DeleteEdbDataWind(edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `DELETE FROM edb_data_wind WHERE edb_code=? `
-	_, err = o.Raw(sql, edbCode).Exec()
-	return
-}
-
-func ModifyEdbDataWind(edbInfoId int64, dataTime string, value float64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_wind SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-func GetEdbDataWindByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_wind WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, size).QueryRows(&items)
-	return
-}
-
-func GetEdbDataWindMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_wind WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-func GetEdbDataWindByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_wind WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-type EdbDataFromWind struct {
-	Close  map[string]float64 `json:"CLOSE"`
-	Dt     map[string]int64   `json:"DT"`
-	ErrMsg string
-}
-
-func RefreshAllEdbDataByWind(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	fmt.Println("wind start:", time.Now())
-	thsUrl := utils.Hz_Data_Url + `edbInfo/wind?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	utils.FileLog.Info("wind %s", string(body))
-	fmt.Println("wind end:", time.Now())
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromWind)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_wind(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	existDataMap := make(map[string]string)
-	fmt.Println("start for:", time.Now())
-	for k, v := range item.Dt {
-		timeStr := fmt.Sprintf("%d", v)
-
-		v = v / 1000
-		t := time.Unix(v, 0)
-		dateTime := t.Format(utils.FormatDate)
-		val := item.Close[k]
-		saveVal := utils.SubFloatToString(val, 30)
-		if existVal, ok := dataMap[dateTime]; !ok {
-			if _, existOk := existDataMap[dateTime]; !existOk {
-				isAdd = true
-				addSql += GetAddSql(edbInfoIdStr, edbCode, dateTime, timeStr, saveVal)
-			}
-			existDataMap[dateTime] = dateTime
-		} else {
-			if existVal != saveVal {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, saveVal, edbInfoId, dateTime).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	fmt.Println("end for:", time.Now())
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			fmt.Println("RefreshAllEdbDataByWind add Err", err.Error())
-			return
-		}
-	}
-	return
-}

+ 0 - 547
models/data_manage/edb_data_ys.go

@@ -1,547 +0,0 @@
-/**
-* @Author: jgl
-* @Date: 2021/9/14 13:33
- */
-
-package data_manage
-
-import (
-	"crypto/md5"
-	"encoding/hex"
-	"encoding/json"
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"io/ioutil"
-	"net/http"
-	"net/url"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type BaseFromSmmDataSimple struct {
-	SmmDataId          int `orm:"column(smm_data_id);pk"`
-	BaseFromSmmIndexId int
-	IndexCode          string
-	DataTime           string
-	Value              string
-}
-
-func GetEdbDataYsMaxAndMinDate(edbCode string) (min_date, max_date string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ys WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
-	return
-}
-
-//有色
-func GetEdbDataByYs(edbCode, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	smmBaseDataAll, err := GetBaseFromSmmDataAllByIndexCode(edbCode)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_ys(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range smmBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.Value)
-			isAdd = true
-		}
-		existMap[eDate] = sv.Value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataThsByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataYsMaxAndMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-//全部刷新有色数据
-func RefreshAllEdbDataByYs(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//获取数据
-	err = SyncSmmIndexDataBase(edbCode, startDate, endDate)
-	if err != nil {
-		err = errors.New("SyncSmmIndexDataBase Err:" + err.Error())
-		return err
-	}
-	//获取已存在指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-
-	smmDateList := make([]*BaseFromSmmDataSimple, 0)
-	smmSql := ` SELECT * FROM base_from_smm_data WHERE index_code=? AND data_time>=? `
-	_, err = o.Raw(smmSql, edbCode, startDate).QueryRows(&smmDateList)
-	if err != nil {
-		return err
-	}
-
-	addSql := ` INSERT INTO edb_data_ys(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for _, sv := range smmDateList {
-		if existVal, ok := existDataMap[sv.DataTime]; !ok {
-			dataTime, err := time.Parse(utils.FormatDate, sv.DataTime)
-			if err != nil {
-				return err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += GetAddSql(edbInfoIdStr, edbCode, sv.DataTime, timeStr, sv.Value)
-			isAdd = true
-		} else {
-			if existVal != sv.Value {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, sv.Value, edbInfoId, sv.DataTime).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-func SyncSmmIndexDataBase(edbCode, startDate, endDate string) (err error) {
-	utils.FileLog.Info("start:" + time.Now().Format(utils.FormatDateTime))
-
-	var smmCode string
-	if strings.Contains(edbCode, "#") {
-		smmCode = strings.Split(edbCode, "#")[0]
-	} else {
-		smmCode = edbCode
-	}
-	token, err := getToken("pqian@hzinsights.com", "hz123456")
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	baseSmmItem, err := GetBaseFromSmmBySmmCode(smmCode)
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-
-	if baseSmmItem == nil {
-		err = errors.New("GetBaseFromSmmBySmmCode Err:" + err.Error())
-		return
-	}
-
-	smmIndexAll, err := GetBaseFromSmmIndexBySmmCode(smmCode)
-	if err != nil {
-		fmt.Println("GetBaseFromSmmIndex Err:" + err.Error())
-		return
-	}
-	existIndexMap := make(map[string]*BaseFromSmmIndex)
-	for _, item := range smmIndexAll {
-		existIndexMap[item.IndexCode] = item
-	}
-
-	ysItem, err := getApiData(token, edbCode, startDate, endDate)
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	if ysItem != nil && ysItem.Code == 200 {
-
-		frequency := ysItem.Data.Frequency
-
-		indexMap := make(map[string]int)
-		smmIndexIdMap := make(map[int]int)
-		indexCodeMap := make(map[int]string)
-
-		indexKey := 0
-		var isDateIndex int
-		for fk, fv := range ysItem.Data.Field {
-			if fv.IsDate == "1" {
-				isDateIndex = fk
-			} else {
-				if !strings.Contains(fv.Name, "产品名称") &&
-					!strings.Contains(fv.Name, "单位") &&
-					!strings.Contains(fv.Name, "时间") &&
-					!strings.Contains(fv.Name, "备注") {
-
-					indexMap[fv.DBColName] = fk
-
-					indexKey += 1
-					indexCode := smmCode + "#" + strconv.Itoa(indexKey)
-
-					if findItem, ok := existIndexMap[indexCode]; !ok {
-						ssmIndex := new(BaseFromSmmIndex)
-						ssmIndex.Interface = smmCode
-						ssmIndex.Name = baseSmmItem.Name
-						ssmIndex.IndexCode = indexCode
-						ssmIndex.IndexName = baseSmmItem.Name + "_" + fv.Name
-						ssmIndex.Type1 = baseSmmItem.Type1
-						ssmIndex.Type2 = baseSmmItem.Type2
-						ssmIndex.Type3 = baseSmmItem.Type3
-						ssmIndex.Frequency = frequency
-						ssmIndex.Unit = fv.Unit
-						ssmIndex.ApiStartTime = baseSmmItem.ApiStartTime
-						ssmIndex.ApiUpdateTime = baseSmmItem.ApiUpdateTime
-						ssmIndex.StartTime = baseSmmItem.StartTime
-						ssmIndex.FinishTime = baseSmmItem.FinishTime
-						ssmIndex.CreateTime = time.Now()
-						ssmIndex.ModifyTime = time.Now()
-						lastIndexId, err := AddBaseFromSmmIndex(ssmIndex)
-						if err != nil {
-							err = errors.New("AddBaseFromSmmIndex Err:" + err.Error())
-							return err
-						}
-						smmIndexIdMap[fk] = int(lastIndexId)
-						indexCodeMap[fk] = indexCode
-					} else {
-						smmIndexIdMap[fk] = findItem.BaseFromSmmIndexId
-						indexCodeMap[fk] = findItem.IndexCode
-					}
-				}
-			}
-		}
-
-		existDataMap := make(map[string]*BaseFromSmmData)
-		for _, mv := range indexCodeMap {
-			indexCode := mv
-			dataAllList, err := GetBaseFromSmmDataAllByIndexCode(indexCode)
-			if err != nil {
-				err = errors.New("GetBaseFromSmmData Err:" + err.Error())
-				return err
-			}
-			for _, item := range dataAllList {
-				key := item.IndexCode + item.DataTime
-				existDataMap[key] = item
-			}
-		}
-
-		addExistDataMap := make(map[string]string)
-
-		for _, dv := range ysItem.Data.Content {
-			var dataTime string
-			dataTime = dv[isDateIndex]
-			if strings.Contains(dataTime, "Q1") {
-				dataTime = strings.Replace(dataTime, "Q1", "-01", -1)
-				dataTime += "-31"
-			}
-			if strings.Contains(dataTime, "Q2") {
-				dataTime = strings.Replace(dataTime, "Q2", "-06", -1)
-				dataTime += "-30"
-			}
-			if strings.Contains(dataTime, "Q3") {
-				dataTime = strings.Replace(dataTime, "Q3", "-09", -1)
-				dataTime += "-30"
-			}
-			if strings.Contains(dataTime, "Q4") {
-				dataTime = strings.Replace(dataTime, "Q4", "-12", -1)
-				dataTime += "-31"
-			}
-
-			if strings.Contains(dataTime, "H1") {
-				dataTime = strings.Replace(dataTime, "H1", "-06", -1)
-				dataTime += "-30"
-			}
-
-			if strings.Contains(dataTime, "H2") {
-				dataTime = strings.Replace(dataTime, "H2", "-12", -1)
-				dataTime += "-31"
-			}
-
-			if frequency == "月" {
-				monthDate, err := time.Parse("2006-01", dataTime)
-				if err != nil {
-					fmt.Println("time.Parse:" + err.Error())
-				}
-				lastTime := monthDate.AddDate(0, 1, -1)
-				lastYear, lastMonth, lastDay := lastTime.Date()
-				var lastDate string
-				if int(lastMonth) < 10 {
-					lastDate = strconv.Itoa(lastYear) + "-" + "0" + strconv.Itoa(int(lastMonth)) + "-" + strconv.Itoa(lastDay)
-				} else {
-					lastDate = strconv.Itoa(lastYear) + "-" + strconv.Itoa(int(lastMonth)) + "-" + strconv.Itoa(lastDay)
-				}
-				dataTime = lastDate
-			} else if frequency == "年" {
-				dataTime = dataTime + "-12-31"
-			}
-			saveDataTime, err := time.Parse(utils.FormatDate, dataTime)
-			if err != nil {
-				err = errors.New("time.Parse Err:" + err.Error())
-				return err
-			}
-			timestamp := saveDataTime.UnixNano() / 1e6
-			//循环指标
-			for _, v := range indexMap {
-
-				indexCode := indexCodeMap[v]
-				smmIndexId := smmIndexIdMap[v]
-				dataVal := dv[v]
-
-				if indexCode != "" {
-
-					key := indexCode + dataTime
-					val := strings.Replace(dataVal, ",", "", -1)
-					if findData, dataOk := existDataMap[key]; !dataOk {
-						if _, addOK := addExistDataMap[key]; !addOK {
-							if val != "" && val != "-" {
-								dataItem := new(BaseFromSmmData)
-								dataItem.BaseFromSmmIndexId = smmIndexId
-								dataItem.IndexCode = indexCode
-								dataItem.DataTime = dataTime
-								dataItem.Value = val
-								dataItem.CreateTime = time.Now()
-								dataItem.ModifyTime = time.Now()
-								dataItem.DataTimestamp = timestamp
-								_, err = AddBaseFromSmmData(dataItem)
-								if err != nil && !strings.Contains(err.Error(), "idx_index_code_date") {
-									fmt.Println("AddBaseFromSmmData Err:" + err.Error())
-									err = errors.New("AddBaseFromSmmData Err:" + err.Error())
-									return err
-								}
-							}
-						}
-					} else {
-						if findData != nil && findData.Value != val { //修改
-							if _, addOK := addExistDataMap[key]; !addOK {
-								if val != "" && val != "-" {
-									err = ModifyBaseFromSmmData(findData.SmmDataId, val)
-									if err != nil {
-										err = errors.New("ModifyBaseFromSmmData Err:" + err.Error())
-										return err
-									}
-								}
-							}
-						}
-					}
-					addExistDataMap[key] = key
-				}
-			}
-		}
-
-		//修改数据开始,结束日期
-		{
-			indexList, err := GetBaseFromSmmIndexBySmmCode(smmCode)
-			if err != nil {
-				fmt.Println("GetBaseFromSmmIndexBySmmCode Err:" + err.Error())
-			}
-			for _, sv := range indexList {
-				minDate, maxDate, err := GetBaseFromSmmMaxOrMinDate(sv.IndexCode)
-				if err != nil {
-					fmt.Println("GetEdbDataSmmMaxOrMinDate Err:" + err.Error())
-				} else {
-					err = ModifyBaseFromSmmMinDateAndMaxDate(sv.BaseFromSmmIndexId, minDate, maxDate)
-					if err != nil {
-						fmt.Println("ModifyBaseFromSmmMinDateAndMaxDate Err:" + err.Error())
-					}
-				}
-			}
-		}
-	}
-	return
-}
-
-const (
-	dataUrl = "https://dataapi.smm.cn/GetData/" //data url (中文)
-	//dataUrl = "https://dataapi.smm.cn/GetDataEn/" //data url (english edition)
-	authUrl = "https://platform.smm.cn/usercenter/auth" // auth url (for all)
-)
-
-type TokenResp struct {
-	Code int       `json:"Code"`
-	Msg  string    `json:"Msg"`
-	Data TokenData `json:"Data"`
-}
-
-type TokenData struct {
-	Token string `json:"Token"`
-}
-
-//获取token
-func getToken(userName string, password string) (string, error) {
-	encryptAuth := md5.New()
-	encryptAuth.Write([]byte(password)) //encrypt password with md5
-	newPassword := hex.EncodeToString(encryptAuth.Sum(nil))
-
-	resp, err := http.PostForm(authUrl, url.Values{"user_name": {userName}, "password": {newPassword}})
-	if err != nil {
-		return "", err
-	}
-
-	defer resp.Body.Close()
-
-	body, err := ioutil.ReadAll(resp.Body)
-	if err != nil {
-		fmt.Println("reponse error", err)
-		return "", err
-	}
-
-	var bodyJsonContent TokenResp
-
-	if err = json.Unmarshal([]byte(body), &bodyJsonContent); err != nil {
-		fmt.Println(err, "unmarsal failure")
-		return "", err
-	}
-
-	var token string
-	if bodyJsonContent.Code == 0 {
-		token = bodyJsonContent.Data.Token
-	}
-
-	//print(token)
-	return token, nil
-}
-
-//request response
-type DataResp struct {
-	Code int      `json:"Code"`
-	Msg  string   `json:"Msg"`
-	Data *ApiData `json:"Data"`
-}
-
-//api data response
-type ApiData struct {
-	Status  int        `json:"Status"` //0 no permission,1 ok
-	Field   []ApiField `json:"Field"`
-	Content [][]string `json:"Content"`
-}
-
-//api title
-type ApiField struct {
-	Unit       string `json:"Unit"`
-	Info       string `json:"Info"`
-	Name       string `json:"Name"`
-	ColumnType string `json:"ColumnType"`
-	ColIndex   uint   `json:"ColIndex"`
-	IsDate     string `json:"IsDate"`
-}
-
-type YsResult struct {
-	Code int64 `json:"Code"`
-	Data struct {
-		CompanyList []interface{} `json:"CompanyList"`
-		Content     [][]string    `json:"Content"`
-		Field       []struct {
-			ColIndex   int64  `json:"ColIndex"`
-			ColumnType string `json:"ColumnType"`
-			Info       string `json:"Info"`
-			IsDate     string `json:"IsDate"`
-			Name       string `json:"Name"`
-			Unit       string `json:"Unit"`
-			DBColName  string `json:"db_col_name"`
-		} `json:"Field"`
-		CountPage   int64  `json:"count_page"`
-		CurrentPage int64  `json:"current_page"`
-		Frequency   string `json:"frequency"`
-		Mindate     string `json:"mindate"`
-		PageNum     int64  `json:"page_num"`
-		Status      int64  `json:"status"`
-		TotalNum    int64  `json:"total_num"`
-	} `json:"Data"`
-	Msg string `json:"Msg"`
-}
-
-/*
- * request data
- * sdatetime,edatetime ==>format:yyyy-mm-dd,
- * apiName ==> data.metal.com(for english)/data.smm.cn (for chinese)
- */
-func getApiData(token string, apiName string, sdatetime string, edatetime string) (item *YsResult, err error) {
-	reqUrl := dataUrl + apiName
-	resp, err := http.PostForm(reqUrl, url.Values{"token": {token}, "sdatetime": {sdatetime}, "edatetime": {edatetime}})
-	if err != nil {
-		return nil, err
-	}
-
-	defer resp.Body.Close()
-	body, err := ioutil.ReadAll(resp.Body)
-	if err != nil {
-		fmt.Println("response error")
-		return nil, err
-	}
-	utils.FileLog.Info("ys result:" + string(body))
-	dataJsonContent := new(YsResult)
-	if err = json.Unmarshal([]byte(body), &dataJsonContent); err != nil {
-		fmt.Println(err, "data unmarshal failure")
-		return nil, err
-	}
-
-	if dataJsonContent.Code == 200 && len(dataJsonContent.Data.Content) > 0 {
-		return dataJsonContent, nil
-	} else {
-		err = errors.New("code:" + strconv.Itoa(int(dataJsonContent.Code)) + "msg:" + dataJsonContent.Msg)
-	}
-	return nil, nil
-}

+ 0 - 423
models/data_manage/edb_data_zz.go

@@ -1,423 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type ZzData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-type BaseFromZzDataSimple struct {
-	Id        int `orm:"column(base_from_trade_zhengzhou_index_id);pk"`
-	DealCode  string
-	BuyCode   string
-	SoldCode  string
-	DataTime  string
-	DealValue string
-	BuyValue  string
-	SoldValue string
-}
-
-type BaseInfoFromZz struct {
-	DealName string
-	BuyName  string
-	SoldName string
-}
-
-type BaseFromTradeZhengzhouIndex struct {
-	BaseFromTradeZhengzhouIndexId int `orm:"column(base_from_trade_zhengzhou_index_id);pk"`
-	Rank                          int
-	DealShortName                 string
-	DealName                      string
-	DealCode                      string
-	DealValue                     string
-	DealChange                    int
-	BuyShortName                  string
-	BuyName                       string
-	BuyCode                       string
-	BuyValue                      string
-	BuyChange                     int
-	SoldShortName                 string
-	SoldName                      string
-	SoldCode                      string
-	SoldValue                     string
-	SoldChange                    int
-	Frequency                     string
-	ClassifyName                  string
-	ClassifyType                  string
-	CreateTime                    time.Time
-	ModifyTime                    time.Time
-	DataTime                      string
-}
-
-func GetEdbDataZzMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_zz WHERE edb_code=? `
-	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
-	return
-}
-
-func GetEdbDataByZz(edbCode, suffix, startDate, endDate string) (searchItem *EdbInfoSearch, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	searchItem = new(EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	zzBaseDataAll, err := GetBaseFromZhengzhouDataAllByIndexCode(edbCode, suffix)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_zz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	dataList := make([]*EdbInfoSearchData, 0)
-	existMap := make(map[string]string)
-
-	for _, sv := range zzBaseDataAll {
-		eDate := sv.DataTime
-		dataTime, err := time.Parse(utils.FormatDate, eDate)
-		if err != nil {
-			fmt.Println("time.Parse Err:" + eDate)
-			return nil, err
-		}
-		timestamp := dataTime.UnixNano() / 1e6
-		timeStr := fmt.Sprintf("%d", timestamp)
-		if _, ok := existMap[eDate]; !ok {
-			if suffix == "deal" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
-			} else if suffix == "buy" {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
-			} else {
-				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
-			}
-			isAdd = true
-		}
-		if suffix == "deal" {
-			existMap[eDate] = sv.DealValue
-		} else if suffix == "buy" {
-			existMap[eDate] = sv.BuyValue
-		} else {
-			existMap[eDate] = sv.SoldValue
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return searchItem, err
-		}
-	}
-	if err != nil {
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_ZZ, size)
-	if err != nil {
-		utils.FileLogData.Info("GetEdbDataZzByCode Err:%s", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := GetEdbDataZzMaxOrMinDate(edbCode)
-	if err != nil {
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*EdbInfoSearchData, 0)
-	}
-	return
-}
-
-// RefreshEdbDataByZz 刷新郑商所指标数据
-func RefreshEdbDataByZz(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetZzDataByTradeCode(condition, pars)
-
-	addSql := ` INSERT INTO edb_data_zz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			count, err := GetEdbDataZzByCodeAndDate(edbCode, v.DataTime)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				eDate := item.DataTime
-				sValue := itemValue
-				if sValue != "" {
-					dataTime, err := time.Parse(utils.FormatDate, eDate)
-					if err != nil {
-						return err
-					}
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
-					isAdd = true
-				}
-			} else {
-				err = ModifyEdbDataZz(int64(edbInfoId), v.DataTime, value)
-				if err != nil {
-					return err
-				}
-			}
-		}
-		existMap[v.DataTime] = value
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// RefreshAllEdbDataByZz 全部刷新郑商所
-func RefreshAllEdbDataByZz(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if err != nil {
-		return
-	}
-	var suffix string
-	if strings.Contains(edbCode, "deal") {
-		suffix = "deal"
-	} else if strings.Contains(edbCode, "buy") {
-		suffix = "buy"
-	} else if strings.Contains(edbCode, "sold") {
-		suffix = "sold"
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-
-	if edbCode != "" {
-		if suffix == "deal" {
-			condition += " AND deal_code=? "
-		} else if suffix == "buy" {
-			condition += " AND buy_code=? "
-		} else {
-			condition += " AND sold_code=? "
-		}
-		pars = append(pars, edbCode)
-	}
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	glDataList, err := GetZzDataByTradeCode(condition, pars)
-
-	//获取指标所有数据
-	dataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range dataList {
-		dataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_zz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, v := range glDataList {
-		var value string
-		if suffix == "deal" {
-			value = v.DealValue
-		} else if suffix == "buy" {
-			value = v.BuyValue
-		} else {
-			value = v.SoldValue
-		}
-		item := v
-		itemValue := value
-		if _, ok := existMap[v.DataTime]; !ok {
-			eDate := item.DataTime
-			sValue := itemValue
-			if sValue != "" {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-					return err
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				saveValue := sValue
-
-				if existVal, ok := dataMap[eDate]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
-					isAdd = true
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-		existMap[v.DataTime] = v.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-// GetBaseInfoFromZhengzhouByIndexCode 获取指标信息
-func GetBaseInfoFromZhengzhouByIndexCode(indexCode, suffix string) (list []*BaseInfoFromZz, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_zhengzhou_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetZzDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromZzDataSimple, err error) {
-	sql := ` SELECT * FROM base_from_trade_zhengzhou_index WHERE 1=1 `
-	o := orm.NewOrm()
-	o.Using("data")
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func AddEdbDataZzBySql(sqlStr string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sqlStr).Exec()
-	return
-}
-
-func GetEdbDataZzByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_data_zz WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
-	_, err = o.Raw(sql, edbCode, utils.EDB_DATA_LIMIT).QueryRows(&items)
-	return
-}
-
-func GetBaseFromZhengzhouDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeZhengzhouIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM base_from_trade_zhengzhou_index WHERE %s_code=? `
-	sql = fmt.Sprintf(sql, suffix)
-	_, err = o.Raw(sql, indexCode).QueryRows(&list)
-	return
-}
-
-func GetEdbDataZzByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_zz WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataZz(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_zz SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}

+ 3 - 871
models/data_manage/edb_info.go

@@ -2,11 +2,7 @@ package data_manage
 
 import (
 	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"strconv"
-	"strings"
+	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -36,312 +32,6 @@ type EdbInfo struct {
 	MoveFrequency    string  `description:"移动频度"`
 }
 
-func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type EdbInfoItem struct {
-	EdbInfoId  int    `description:"指标id"`
-	EdbName    string `description:"指标名称"`
-	ClassifyId int    `description:"指标分类"`
-}
-
-//用于分类展示
-func GetEdbInfoAll() (items []*EdbClassifyItems, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT edb_info_id,classify_id,edb_name_source AS classify_name,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type FROM edb_info order by sort asc,edb_info_id asc`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//用于分类展示
-func GetEdbInfoAllList() (items []*EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//指标检索数据
-type EdbInfoSearch struct {
-	EdbCode   string `description:"指标编码"`
-	StartDate string `description:"起始日期"`
-	EndDate   string `description:"终止日期"`
-	EdbName   string `description:"指标名称"`
-	Unit      string `description:"单位"`
-	Frequency string `description:"频率"`
-	DataList  []*EdbInfoSearchData
-}
-
-type EdbInfoSearchData struct {
-	DataTime string  `description:"数据日期"`
-	Value    float64 `description:"数据"`
-}
-
-type EdbInfoSearchResp struct {
-	SearchItem   *EdbInfoSearch `description:"指标分类"`
-	Status       int            `description:"1:数据已存在于弘则数据库,2:新数据"`
-	ClassifyList []*EdbClassifySimplify
-}
-
-func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
-	err = o.Raw(sql, source, edbCode).QueryRow(&item)
-	return
-}
-
-func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-type AddEdbInfoReq struct {
-	Source     int    `description:"来源id"`
-	EdbCode    string `description:"指标编码"`
-	EdbName    string `description:"指标名称"`
-	Frequency  string `description:"频率"`
-	Unit       string `description:"单位"`
-	ClassifyId int    `description:"分类id"`
-	StartDate  string `description:"起始日期"`
-	EndDate    string `description:"终止日期"`
-}
-
-func DeleteEdbInfoAndData(edbInfoId, source int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	sql := ` DELETE FROM edb_info WHERE edb_info_id=? `
-	_, err = o.Raw(sql, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-	tableName := GetEdbDataTableName(source)
-	if tableName != "" {
-		sql = ` DELETE FROM %s WHERE edb_info_id=? `
-		sql = fmt.Sprintf(sql, tableName)
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return
-		}
-	}
-	//calculateTableName := GetEdbInfoCalculateTableName(source)
-	//if calculateTableName != "" {
-	//	sql = ` DELETE FROM %s WHERE edb_info_id=? `
-	//	sql = fmt.Sprintf(sql, calculateTableName)
-	//	_, err = o.Raw(sql, edbInfoId).Exec()
-	//	return
-	//}
-	//return
-	sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
-	_, err = o.Raw(sql, edbInfoId).Exec()
-	return
-}
-
-func GetEdbInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-type EditEdbInfoReq struct {
-	EdbInfoId        int    `description:"指标ID"`
-	EdbName          string `description:"指标名称"`
-	Frequency        string `description:"频率"`
-	Unit             string `description:"单位"`
-	ClassifyId       int    `description:"分类id"`
-	CalculateFormula string `description:"计算公式"`
-}
-
-func ModifyEdbInfo(item *EditEdbInfoReq) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source =?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ?`
-	_, err = o.Raw(sql, item.EdbName, item.EdbName, item.Frequency, item.Unit, item.ClassifyId, item.EdbInfoId).Exec()
-	return
-}
-
-type EdbInfoList struct {
-	EdbInfoId       int    `orm:"column(edb_info_id);pk"`
-	SourceName      string `description:"来源名称"`
-	Source          int    `description:"来源id"`
-	EdbCode         string `description:"指标编码"`
-	EdbName         string `description:"指标名称"`
-	Frequency       string `description:"频率"`
-	Unit            string `description:"单位"`
-	StartDate       string `description:"起始日期"`
-	EndDate         string `description:"终止日期"`
-	ClassifyId      int    `description:"分类id"`
-	UniqueCode      string `description:"指标唯一编码"`
-	SysUserId       int    `description:"创建人id"`
-	SysUserRealName string `description:"创建人姓名"`
-	ModifyTime      string `description:"最新修改时间"`
-	EdbNameAlias    string `json:"-" description:"指标名称,别名"`
-	EdbType         int    `description:"指标类型:1:基础指标,2:计算指标"`
-	DataList        []*EdbData
-}
-
-type EdbData struct {
-	EdbDataId int `orm:"column(edb_data_id);pk"`
-	EdbInfoId int
-	DataTime  string
-	Value     float64
-}
-
-type EdbInfoListResp struct {
-	Paging       *paging.PagingItem
-	Item         *EdbInfoList
-	ClassifyList []*EdbClassifySimplify
-}
-
-func GetEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfoList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&item)
-	return
-}
-
-func GetEdbDataCountByCondition(condition string, pars []interface{}, source int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	tableName := GetEdbDataTableName(source)
-	sql := ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 AND status=1 `
-	sql = fmt.Sprintf(sql, tableName)
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-func GetEdbDataListByCondition(condition string, pars []interface{}, source, pageSize, startSize int) (item []*EdbData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	tableName := GetEdbDataTableName(source)
-	sql := ` SELECT * FROM %s WHERE 1=1 AND status=1 `
-	sql = fmt.Sprintf(sql, tableName)
-
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	sql += ` LIMIT ?,? `
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
-	return
-}
-
-func GetEdbInfoByNewest() (item *EdbInfoList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE 1=1 ORDER BY modify_time DESC LIMIT 1 `
-	err = o.Raw(sql).QueryRow(&item)
-	return
-}
-
-func ModifyEdbInfoModifyTime(edbInfoId int64) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  edb_info SET modify_time = NOW() WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, edbInfoId).Exec()
-	return
-}
-
-type MoveEdbInfoReq struct {
-	EdbInfoId     int `description:"指标ID"`
-	PrevEdbInfoId int `description:"上一个指标ID"`
-	NextEdbInfoId int `description:"下一个指标ID"`
-	ClassifyId    int `description:"分类id"`
-}
-
-func MoveEdbInfo(edbInfoId, classifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  edb_info
-			SET
-			  classify_id = ?
-			WHERE edb_info_id = ?`
-	_, err = o.Raw(sql, classifyId, edbInfoId).Exec()
-	return
-}
-
-func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE edb_name=? `
-	_, err = o.Raw(sql, edbName).QueryRows(&items)
-	return
-}
-
-func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  edb_info SET edb_name_source=? WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, edbNameSource, edbInfoId).Exec()
-	return
-}
-
-func GetChartEdbMappingCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-type ChartEdbInfo struct {
-	EdbInfoId    int    `description:"指标id"`
-	EdbName      string `description:"指标名称"`
-	SourceName   string `json:"-"`
-	EdbNameAlias string `json:"-" description:"指标名称,别名"`
-}
-
-func EdbInfoSearchByKeyWord(KeyWord string) (searchList []*ChartEdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT edb_info_id,edb_name,source_name FROM edb_info `
-	if KeyWord != "" {
-		sql += `WHERE (edb_name LIKE '%` + KeyWord + `%' OR edb_code LIKE '%` + KeyWord + `%' ) `
-	}
-	sql += ` ORDER BY create_time DESC `
-	_, err = o.Raw(sql).QueryRows(&searchList)
-
-	return
-}
-
 type EdbInfoMaxAndMinInfo struct {
 	MinDate     string  `description:"最小日期"`
 	MaxDate     string  `description:"最大日期"`
@@ -351,8 +41,7 @@ type EdbInfoMaxAndMinInfo struct {
 }
 
 func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	sql := ``
 	tableName := GetEdbDataTableName(source)
 	sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
@@ -368,565 +57,8 @@ func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMin
 }
 
 func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
 	_, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
 	return
 }
-
-func GetEdbInfoFilter(condition string, pars []interface{}) (list []*EdbInfoList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY create_time DESC `
-	_, err = o.Raw(sql, pars).QueryRows(&list)
-	return
-}
-
-//order:1升序,其余值为降序
-func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ``
-	tableName := GetEdbDataTableName(source)
-	sql = ` SELECT * FROM %s WHERE 1=1 `
-	sql = fmt.Sprintf(sql, tableName)
-
-	if condition != "" {
-		sql += condition
-	}
-	if order == 1 {
-		sql += ` ORDER BY data_time ASC `
-	} else {
-		sql += ` ORDER BY data_time DESC `
-	}
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-// GetLastEdbData 获取最近的一条指标数据
-func GetLastEdbData(condition string, pars []interface{}, source int) (item *EdbInfoSearchData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ``
-	tableName := GetEdbDataTableName(source)
-	sql = ` SELECT * FROM %s WHERE 1=1 `
-	sql = fmt.Sprintf(sql, tableName)
-
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` ORDER BY data_time DESC `
-	err = o.Raw(sql, pars).QueryRow(&item)
-	return
-}
-
-//order:1升序,其余值为降序
-func GetEdbDataCount(condition string, pars []interface{}, source int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ``
-	tableName := GetEdbDataTableName(source)
-	sql = ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
-	sql = fmt.Sprintf(sql, tableName)
-
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-func ModifyCalculateEdbInfo(item *EditEdbInfoReq) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source =?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ?`
-	_, err = o.Raw(sql, item.EdbName, item.EdbName, item.Frequency, item.Unit, item.ClassifyId, item.CalculateFormula, item.EdbInfoId).Exec()
-	return
-}
-
-type AddEdbInfoResp struct {
-	EdbInfoId  int    `description:"指标ID"`
-	UniqueCode string `description:"指标唯一编码"`
-}
-
-//根据基础指标获取所有关联指标
-func GetNeedRefreshCalculateEdbInfoFromBase(fromEdbInfo int) (list []*EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT b.*
-			FROM edb_info_calculate AS a
-			INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
-			WHERE from_edb_info_id=? `
-	_, err = o.Raw(sql, fromEdbInfo).QueryRows(&list)
-	return
-}
-
-func GetEdbInfoCalculateCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-func GetEdbInfoCalculateLjzzyCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_ljzzy WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-func GetEdbInfoCalculateTbzCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_tbz WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-func GetEdbInfoCalculateTczCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_tcz WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-func GetEdbInfoCalculateNszydpjjsCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_nszydpjjs WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-func GetEdbInfoCalculateCountByCondition(source int, condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	//calculateTableName := GetEdbInfoCalculateTableName(source)
-	//if calculateTableName == "" {
-	//	err = errors.New("无效的表名")
-	//	return
-	//}
-
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE 1=1 `
-	//sql = fmt.Sprintf(sql, calculateTableName)
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-// GetEdbInfoCalculateListByCondition 获取指标关系列表
-func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	//calculateTableName := GetEdbInfoCalculateTableName(source)
-	//if calculateTableName == "" {
-	//	err = errors.New("无效的表名")
-	//	return
-	//}
-
-	sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
-	//sql = fmt.Sprintf(sql, calculateTableName)
-	if condition != "" {
-		sql += condition
-	}
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-func GetRefreshEdbInfoFromCalculate(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
-	calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-	for _, item := range calculateList {
-		if item.EdbType == 1 {
-			baseEdbInfoArr = append(baseEdbInfoArr, item)
-		} else {
-			calculateInfoArr = append(calculateInfoArr, item)
-			newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromCalculate(item.EdbInfoId, item.Source)
-			baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
-			calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
-		}
-	}
-	return
-}
-
-//获取基础指标对应的所有计算指标
-func GetEdbInfoAllCalculate(edbInfoId int) (list []*EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date,b.frequency FROM edb_info_calculate_mapping AS a
-			 INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
-             WHERE a.from_edb_info_id=?
-			 GROUP BY a.edb_info_id
-			 ORDER BY a.edb_info_id ASC `
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)
-	return
-}
-
-func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
-	calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-	for _, item := range calculateList {
-		if item.EdbType == 1 {
-			baseEdbInfoArr = append(baseEdbInfoArr, item)
-		} else {
-			calculateInfoArr = append(calculateInfoArr, item)
-			newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
-			baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
-			calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
-		}
-	}
-	return
-}
-
-func ModifyEdbInfoDataStatus(edbInfoId int64, source int, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ``
-	tableName := GetEdbDataTableName(source)
-	sql = ` UPDATE %s SET edb_info_id=?, status=1,modify_time=NOW() WHERE edb_code=? `
-	sql = fmt.Sprintf(sql, tableName)
-	_, err = o.Raw(sql, edbInfoId, edbCode).Exec()
-	return
-}
-
-// GetFirstEdbInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
-func GetFirstEdbInfoByClassifyId(classifyId int) (item *EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info WHERE classify_id=? order by sort asc,edb_info_id asc limit 1`
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-// UpdateEdbInfoSortByClassifyId 根据分类id更新排序
-func UpdateEdbInfoSortByClassifyId(classifyId, nowSort int, prevEdbInfoId int, updateSort string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=? and sort > ?`
-	if prevEdbInfoId > 0 {
-		sql += ` or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` ) `
-	}
-	_, err = o.Raw(sql, classifyId, nowSort).Exec()
-	return
-}
-
-// Update 更新指标基础信息
-func (edbInfo *EdbInfo) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Update(edbInfo, cols...)
-	return
-}
-
-type EdbInfoDataResp struct {
-	EdbInfo  *EdbInfo
-	DataList []*EdbDataList
-}
-
-type EdbInfoReplaceReq struct {
-	OldEdbInfoId int `description:"原指标ID"`
-	NewEdbInfoId int `description:"替换为指标ID"`
-}
-
-/*
-1、替换图库中的指标
-2、替换计算指标中的指标,完了计算指标中的指标,全部重新计算
-*/
-
-func EdbInfoReplace(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRealName string) (replaceChartTotal, replaceCalculateTotal int, err error) {
-	var errmsg string
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if errmsg != "" {
-			fmt.Println("errmsg:" + errmsg)
-		}
-	}()
-	//替换图表
-	chartEdbMappingList := make([]*ChartEdbInfoMapping, 0)
-	csql := `SELECT * FROM chart_edb_mapping WHERE edb_info_id=?`
-	_, err = o.Raw(csql, oldEdbInfo.EdbInfoId).QueryRows(&chartEdbMappingList)
-	if err != nil {
-		errmsg = "获取指标关联图表信息失败:Err:" + err.Error()
-		return
-	}
-	replaceChartTotal = len(chartEdbMappingList)
-
-	for _, mv := range chartEdbMappingList {
-		//获取图表所有指标信息
-		chartEdbList := make([]*ChartEdbInfoMapping, 0)
-		csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=?`
-		_, err = o.Raw(csql, mv.ChartInfoId).QueryRows(&chartEdbList)
-		if err != nil {
-			errmsg = "获取图表所有指标信息失败:Err:" + err.Error()
-			return
-		}
-		var minData, maxData float64
-		minData = newEdbInfo.MinValue
-		maxData = newEdbInfo.MaxValue
-
-		for _, cv := range chartEdbList {
-			if mv.IsAxis == cv.IsAxis {
-				if minData > cv.MinData {
-					minData = cv.MinData
-				}
-				if maxData < cv.MaxData {
-					maxData = cv.MaxData
-				}
-			}
-		}
-		//修改图表关联指标
-		rsql := ` UPDATE chart_edb_mapping SET edb_info_id=?,max_data=?,min_data=?,modify_time=NOW() WHERE chart_edb_mapping_id=? `
-		_, err = o.Raw(rsql, newEdbInfo.EdbInfoId, maxData, minData, mv.ChartEdbMappingId).Exec()
-		if err != nil {
-			errmsg = "更新图库指标信息失败:Err:" + err.Error()
-			return
-		}
-	}
-	//替换计算指标
-	//获取所有包含的计算指标
-	mappingList := make([]*EdbInfoCalculateMapping, 0)
-	msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=?  GROUP BY edb_info_id `
-	_, err = o.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&mappingList)
-	if err != nil {
-		errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
-		return
-	}
-	replaceCalculateTotal = len(mappingList)
-	//计算指标
-	for _, mv := range mappingList {
-		//替换原指标
-		msql := `UPDATE edb_info_calculate_mapping SET from_edb_info_id=?,from_edb_code=?,from_edb_name=?,from_source=?,from_source_name=? WHERE edb_info_calculate_mapping_id=? `
-		_, err = o.Raw(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Exec()
-		if err != nil {
-			return
-		}
-	}
-
-	if err != nil && errmsg != "" {
-		go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"替换指标失败提醒", "errmsg:"+errmsg, utils.EmailSendToUsers)
-		o.Rollback()
-	} else {
-		o.Commit()
-	}
-
-	//获取计算指标关联指标
-	allMappingList := make([]*EdbInfoCalculateMapping, 0)
-	allMapping := make(map[int]int)
-	for _, v := range mappingList {
-		if _, ok := allMapping[v.EdbInfoId]; !ok {
-			allMappingList = append(allMappingList, v)
-		}
-		newList, _ := GetAllCalculate(v.EdbInfoId)
-		for _, nv := range newList {
-			if _, ok := allMapping[v.EdbInfoId]; !ok {
-				allMappingList = append(allMappingList, nv)
-			}
-			allMapping[v.EdbInfoId] = v.EdbInfoId
-		}
-		allMapping[v.EdbInfoId] = v.EdbInfoId
-	}
-	for mk, mv := range allMappingList { //原指标关联的所有计算指标
-		fmt.Println("mk/mv", mk, mv)
-		//重新计算计算指标
-		{
-			edbInfo, err := GetEdbInfoById(mv.EdbInfoId) //计算指标
-			if err != nil {
-				if err.Error() == utils.ErrNoRow() {
-					errmsg = "计算指标已被删除"
-					return replaceChartTotal, replaceCalculateTotal, err
-				}
-				errmsg = "获取计算指标失败:err:" + err.Error()
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-
-			fromEdbInfoList, err := GetEdbInfoCalculateDetail(mv.EdbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "获取计算指标失败:err:" + err.Error()
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			if len(fromEdbInfoList) <= 0 {
-				errmsg = "计算指标所依赖指标不存在"
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			fromEdbInfoItem := fromEdbInfoList[0]
-			if fromEdbInfoItem == nil {
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			fromEdbInfo, err := GetEdbInfoById(fromEdbInfoItem.FromEdbInfoId)
-			if err != nil {
-				errmsg = "获取计算指标 来源指标失败:err:" + err.Error()
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			edbCode := edbInfo.EdbCode
-			uniqueCode := edbInfo.UniqueCode
-			sourName := edbInfo.SourceName
-			source := edbInfo.Source
-			edbInfoId := edbInfo.EdbInfoId
-
-			req := new(EdbInfoCalculateBatchSaveReq)
-			req.EdbInfoId = edbInfoId
-			req.EdbName = edbInfo.EdbName
-			req.Frequency = edbInfo.Frequency
-			req.Unit = edbInfo.Unit
-			req.ClassifyId = edbInfo.ClassifyId
-			req.FromEdbInfoId = fromEdbInfoList[0].FromEdbInfoId
-
-			if source == utils.DATA_SOURCE_CALCULATE {
-				//检验公式
-				var formulaStr string
-				var edbInfoIdBytes []string
-				for _, v := range fromEdbInfoList {
-					formulaStr += v.FromTag + ","
-					edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				}
-				formulaStr = strings.Trim(formulaStr, ",")
-				formulaMap := CheckFormula(edbInfo.CalculateFormula)
-				for _, v := range formulaMap {
-					if !strings.Contains(formulaStr, v) {
-						errmsg = "公式错误,请重新填写"
-						return replaceChartTotal, replaceCalculateTotal, err
-					}
-				}
-
-				edbInfoList := make([]*EdbInfo, 0)
-
-				for _, v := range fromEdbInfoList {
-					edbInfo, err := GetEdbInfoById(v.FromEdbInfoId)
-					if err != nil {
-						if err.Error() == utils.ErrNoRow() {
-							errmsg = "指标 " + strconv.Itoa(v.FromEdbInfoId) + " 不存在"
-							return replaceChartTotal, replaceCalculateTotal, err
-						}
-						errmsg = "获取指标失败:Err:" + err.Error()
-						return replaceChartTotal, replaceCalculateTotal, err
-					}
-					edbInfoList = append(edbInfoList, edbInfo)
-				}
-				//清除历史数据
-				err = DeleteCalculateData(edbInfoId)
-				if err != nil {
-					errmsg = "清空运算指标失败:Err:" + err.Error() + " edb_info_id:" + strconv.Itoa(edbInfoId)
-					return replaceChartTotal, replaceCalculateTotal, err
-				}
-				err = Calculate(edbInfoList, int(edbInfoId), edbCode, edbInfo.CalculateFormula, edbInfoIdBytes)
-				if err != nil {
-					errmsg = "生成计算指标失败,Calculate Err:" + err.Error()
-					return replaceChartTotal, replaceCalculateTotal, err
-				}
-			} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY {
-				_, err = AddCalculateLjzzy(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName)
-			} else if source == utils.DATA_SOURCE_CALCULATE_TBZ {
-				sourName = "同比值"
-				edbInfoId, err = AddCalculateTbz(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName)
-			} else if source == utils.DATA_SOURCE_CALCULATE_TCZ {
-				sourName = "同差值"
-				edbInfoId, err = AddCalculateTcz(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName)
-			} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
-				sourName = "N数值移动平均计算"
-				formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-				edbInfoId, err = AddCalculateNszydpjjs(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName, formulaInt)
-			} else if source == utils.DATA_SOURCE_CALCULATE_HBZ {
-				sourName = "环比值"
-				formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-				edbInfoId, err = AddCalculateHbz(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName, formulaInt)
-			} else if source == utils.DATA_SOURCE_CALCULATE_HCZ {
-				sourName = "环差值"
-				formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-				edbInfoId, err = AddCalculateHcz(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName, formulaInt)
-			} else if source == utils.DATA_SOURCE_CALCULATE_BP {
-				sourName = "变频"
-				fmt.Println("变频", req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName)
-				edbInfoId, err = AddCalculateBp(req, fromEdbInfo, edbCode, uniqueCode, sysAdminId, sysAdminRealName)
-			} else {
-				errmsg = "无效计算方式,source:" + strconv.Itoa(source)
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(source, edbCode)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				errmsg = "生成" + sourName + "失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
-				return replaceChartTotal, replaceCalculateTotal, err
-			}
-			if maxAndMinItem != nil {
-				err = ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			}
-		}
-	}
-	return
-}
-
-type EdbInfoView struct {
-	EdbInfoId        int    `orm:"column(edb_info_id);pk"`
-	SourceName       string `description:"来源名称"`
-	Source           int    `description:"来源id"`
-	EdbCode          string `description:"指标编码"`
-	EdbName          string `description:"指标名称"`
-	EdbNameSource    string `description:"指标名称来源"`
-	Frequency        string `description:"频率"`
-	Unit             string `description:"单位"`
-	StartDate        string `description:"起始日期"`
-	EndDate          string `description:"终止日期"`
-	ClassifyId       int    `description:"分类id"`
-	SysUserId        int
-	SysUserRealName  string
-	UniqueCode       string `description:"指标唯一编码"`
-	CreateTime       string
-	ModifyTime       string
-	MinValue         float64 `description:"指标最小值"`
-	MaxValue         float64 `description:"指标最大值"`
-	CalculateFormula string  `description:"计算公式"`
-	EdbType          int     `description:"指标类型:1:基础指标,2:计算指标"`
-	Sort             int     `description:"排序字段"`
-	IsUpdate         int     `description:"当天是否已更新,1:未更新,2:已更新"`
-	LatestDate       string  `description:"数据最新日期"`
-	LatestValue      float64 `description:"数据最新值"`
-}
-
-//获取指标的所有计算指标,以及计算指标所依赖计算指标
-func GetAllCalculateByEdbInfoId(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=?  GROUP BY edb_info_id `
-	_, err = o.Raw(msql, edbInfoId).QueryRows(&mappingList)
-	if err != nil {
-		return
-	}
-	return
-}
-
-func GetAllCalculate(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
-	calculateList, err := GetAllCalculateByEdbInfoId(edbInfoId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return
-	}
-	for _, item := range calculateList {
-		mappingList = append(mappingList, item)
-		newCalculateInfoArr, _ := GetAllCalculate(item.EdbInfoId)
-		mappingList = append(mappingList, newCalculateInfoArr...)
-	}
-	return
-}

+ 2 - 582
models/data_manage/edb_info_calculate.go

@@ -1,190 +1,11 @@
 package data_manage
 
 import (
-	"errors"
-	"fmt"
-	"github.com/yidane/formula"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
+	"github.com/beego/beego/v2/client/orm"
 )
 
-type EdbInfoCalculateSaveReq struct {
-	EdbName          string `description:"指标名称"`
-	Frequency        string `description:"频率"`
-	Unit             string `description:"单位"`
-	ClassifyId       int    `description:"分类id"`
-	CalculateFormula string `description:"计算公式"`
-	EdbInfoIdArr     []struct {
-		EdbInfoId int    `description:"指标id"`
-		FromTag   string `description:"指标对应标签"`
-	}
-}
-
-type EdbInfoCalculate struct {
-	EdbInfoCalculateId int       `orm:"column(edb_info_calculate_id);pk"`
-	EdbInfoId          int       `description:"指标id"`
-	EdbCode            string    `description:"指标编码"`
-	FromEdbInfoId      int       `description:"计算指标id"`
-	FromEdbCode        string    `description:"计算指标编码"`
-	FromEdbName        string    `description:"计算指标名称"`
-	FromSource         int       `description:"计算指标来源"`
-	FromSourceName     string    `description:"计算指标来源名称"`
-	FromTag            string    `description:"来源指标标签"`
-	Sort               int       `description:"计算指标名称排序"`
-	CreateTime         time.Time `description:"创建时间"`
-	ModifyTime         time.Time `description:"修改时间"`
-}
-
-func AddEdbInfoCalculateMulti(items []*EdbInfoCalculate) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-type FromEdbInfoData struct {
-	EdbInfoId int    `description:"指标id"`
-	EdbName   string `description:"指标名称"`
-	DataList  []*EdbInfoSearchData
-}
-
-type EdbInfoCalculateDetail struct {
-	EdbInfoCalculateId int       `orm:"column(edb_info_calculate_id);pk"`
-	EdbInfoId          int       `description:"指标id"`
-	EdbCode            string    `description:"指标编码"`
-	FromEdbInfoId      int       `description:"计算指标id"`
-	FromEdbCode        string    `description:"计算指标编码"`
-	FromEdbName        string    `description:"计算指标名称"`
-	FromSource         int       `description:"计算指标来源"`
-	FromSourceName     string    `description:"计算指标来源名称"`
-	FromTag            string    `description:"来源指标标签"`
-	Sort               int       `description:"计算指标名称排序"`
-	CreateTime         time.Time `description:"创建时间"`
-	ModifyTime         time.Time `description:"修改时间"`
-	StartDate          string    `description:"开始日期"`
-	EndDate            string    `description:"结束日期"`
-	EdbType            int       `description:"指标类型:1:基础指标,2:计算指标"`
-}
-
-func GetEdbInfoCalculateDetail(edbInfoId, source int) (list []*EdbInfoCalculateDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-
-	//calculateTableName := GetEdbInfoCalculateTableName(source)
-	//sql := ` SELECT a.*,b.start_date,b.end_date,b.edb_type FROM %s AS a
-	//		INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-	//		WHERE a.edb_info_id=? ORDER BY sort ASC `
-	//
-	//sql = fmt.Sprintf(sql, calculateTableName)
-
-	sql := ` SELECT a.*,b.start_date,b.end_date,b.edb_type FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? ORDER BY sort ASC `
-
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)
-	return
-}
-
-type CalculateDetailResp struct {
-	EdbInfoDetail *EdbInfo
-	CalculateList []*EdbInfoCalculateDetail
-}
-
-type EdbInfoCalculateEditReq struct {
-	EdbInfoId        int    `description:"指标id"`
-	EdbName          string `description:"指标名称"`
-	Frequency        string `description:"频率"`
-	Unit             string `description:"单位"`
-	ClassifyId       int    `description:"分类id"`
-	CalculateFormula string `description:"计算公式"`
-	EdbInfoIdArr     []struct {
-		EdbInfoId int    `description:"指标id"`
-		FromTag   string `description:"指标对应标签"`
-	}
-}
-
-func GetCalculateEdbInfo(edbInfoId int) (from_edb_info_id string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT GROUP_CONCAT(from_edb_info_id ORDER BY sort ASC SEPARATOR ',') AS from_edb_info_id 
-			FROM edb_info_calculate_mapping
-			WHERE edb_info_id=?
-			GROUP BY edb_info_id
-			 `
-	err = o.Raw(sql, edbInfoId).QueryRow(&from_edb_info_id)
-	return
-}
-
-func DeleteCalculateEdbInfo(edbInfoId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	o.Begin()
-	sql := `DELETE FROM edb_data_calculate WHERE edb_info_id=?`
-	_, err = o.Raw(sql, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-	sql = `DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=?`
-	o.Raw(sql, edbInfoId).Exec()
-	return
-}
-
-func DeleteCalculateData(edbInfoId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `DELETE FROM edb_data_calculate WHERE edb_info_id=?`
-	_, err = o.Raw(sql, edbInfoId).Exec()
-	return
-}
-
-type EdbInfoCalculateBatchSaveReq struct {
-	EdbInfoId        int    `description:"指标id"`
-	EdbName          string `description:"指标名称"`
-	Frequency        string `description:"频度"`
-	Unit             string `description:"单位"`
-	ClassifyId       int    `description:"分类id"`
-	Formula          string `description:"N值/移动天数"`
-	FromEdbInfoId    int    `description:"计算来源指标id"`
-	Source           int    `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
-	CalculateFormula string `description:"计算公式"`
-	EdbInfoIdArr     []struct {
-		EdbInfoId int    `description:"指标id"`
-		FromTag   string `description:"指标对应标签"`
-	}
-	MoveType      int    `description:"移动方式:1:领先(默认),2:滞后"`
-	MoveFrequency string `description:"移动频度:天/周/月/季/年"`
-}
-
-type EdbInfoCalculateBatchEditReq struct {
-	EdbName       string `description:"指标名称"`
-	Frequency     string `description:"频度"`
-	Unit          string `description:"单位"`
-	ClassifyId    int    `description:"分类id"`
-	Formula       string `description:"N值"`
-	EdbInfoId     int    `description:"编辑指标id"`
-	FromEdbInfoId int    `description:"计算来源指标id"`
-	Source        int    `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
-	MoveType      int    `description:"移动方式:1:领先(默认),2:滞后"`
-	MoveFrequency string `description:"移动频度:天/周/月/季/年"`
-	EdbInfoIdArr  []struct {
-		EdbInfoId int    `description:"指标id"`
-		FromTag   string `description:"指标对应标签"`
-	}
-}
-
 func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 
 	//calculateTableName := GetEdbInfoCalculateTableName(source)
 
@@ -200,404 +21,3 @@ func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error)
 	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)
 	return
 }
-
-//指标运算
-func AddCalculate(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo []*EdbInfoCalculateDetail, edbCode, uniqueCode, formulaStr string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE
-		edbInfo.SourceName = "指标运算"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.CalculateFormula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return int(newEdbInfoId), err
-		}
-		edbInfoId = int(newEdbInfoId)
-		//处理同名指标
-		{
-			edbNameList, err := GetEdbInfoByName(req.EdbName)
-			if err != nil {
-				return edbInfoId, err
-			}
-			if len(edbNameList) >= 2 {
-				for _, v := range edbNameList {
-					edbName := v.EdbName + "(" + v.SourceName + ")"
-					err = ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
-					if err != nil {
-						return edbInfoId, err
-					}
-				}
-			}
-		}
-
-		//calculateList := make([]*EdbInfoCalculate, 0)
-		edbInfoList := make([]*EdbInfo, 0)
-
-		for _, v := range req.EdbInfoIdArr {
-			edbInfo, err := GetEdbInfoById(v.EdbInfoId)
-			if err != nil {
-				return edbInfoId, err
-			}
-			//calculateItem := new(EdbInfoCalculate)
-			//calculateItem.CreateTime = time.Now()
-			//calculateItem.ModifyTime = time.Now()
-			//calculateItem.Sort = k + 1
-			//calculateItem.EdbCode = edbCode
-			//calculateItem.EdbInfoId = int(edbInfoId)
-			//calculateItem.FromEdbInfoId = edbInfo.EdbInfoId
-			//calculateItem.FromEdbCode = edbInfo.EdbCode
-			//calculateItem.FromEdbName = edbInfo.EdbName
-			//calculateItem.FromSource = edbInfo.Source
-			//calculateItem.FromSourceName = edbInfo.SourceName
-			//calculateItem.FromTag = v.FromTag
-			//calculateList = append(calculateList, calculateItem)
-			edbInfoList = append(edbInfoList, edbInfo)
-		}
-		//if len(calculateList) > 0 {
-		//	_, err = o.InsertMulti(1, calculateList)
-		//	if err != nil {
-		//		return edbInfoId, err
-		//	}
-		//}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-	//计算数据
-	saveDataMap := make(map[string]map[int]float64)
-	for _, v := range fromEdbInfo {
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, v.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, v.FromSource, 1)
-		if err != nil {
-			return edbInfoId, err
-		}
-		dataMap := make(map[string]float64)
-		for _, dv := range dataList {
-			if val, ok := saveDataMap[dv.DataTime]; ok {
-				if _, ok := val[v.EdbInfoId]; !ok {
-					val[v.EdbInfoId] = dv.Value
-				}
-			} else {
-				temp := make(map[int]float64)
-				temp[v.EdbInfoId] = dv.Value
-				saveDataMap[dv.DataTime] = temp
-			}
-		}
-		item := new(CalculateItems)
-		item.EdbInfoId = v.EdbInfoId
-		item.DataMap = dataMap
-	}
-
-	//formulaMap := CheckFormula(formulaStr)
-	//addSql := ` INSERT INTO edb_data_calculate(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	//nowStr := time.Now().Format(utils.FormatDateTime)
-	//var isAdd bool
-	//
-	//for sk, sv := range saveDataMap {
-	//	formulaStr = strings.ToUpper(formulaStr)
-	//	formulaFormStr := ReplaceFormula(edbInfoIdArr, sv, formulaMap, formulaStr, edbInfoIdBytes)
-	//	if formulaFormStr != "" {
-	//		utils.FileLog.Info("formulaFormStr:%s", formulaFormStr)
-	//		expression := formula.NewExpression(formulaFormStr)
-	//		calResult, err := expression.Evaluate()
-	//		if err != nil {
-	//			err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-	//			fmt.Println(err)
-	//			return err
-	//		}
-	//		calVal, err := calResult.Float64()
-	//		if err != nil {
-	//			err = errors.New("计算失败:获取计算值失败 Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-	//			fmt.Println(err)
-	//			return err
-	//		}
-	//
-	//		//需要存入的数据
-	//		{
-	//			dataTime, _ := time.Parse(utils.FormatDate, sk)
-	//			timestamp := dataTime.UnixNano() / 1e6
-	//			timeStr := fmt.Sprintf("%d", timestamp)
-	//			addSql += "("
-	//			addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + sk + "'" + "," + utils.SubFloatToString(calVal, 4) + "," + "'" + nowStr + "'" +
-	//				"," + "'" + nowStr + "'" + "," + "1"
-	//			addSql += "," + "'" + timeStr + "'"
-	//			addSql += "),"
-	//			isAdd = true
-	//		}
-	//	}
-	//}
-	//if isAdd {
-	//	addSql = strings.TrimRight(addSql, ",")
-	//	AddEdbDataCalculateBySql(addSql)
-	//	if err != nil {
-	//		fmt.Println("AddEdbDataCalculate Err:" + err.Error())
-	//		return
-	//	}
-	//}
-	return
-}
-
-type CalculateItems struct {
-	EdbInfoId int
-	DataMap   map[string]float64
-}
-
-func CheckFormula(formula string) map[string]string {
-	mathFormula := []string{"MAX", "MIN", "ABS", "ACOS", "ASIN", "CEIL", "MOD", "POW", "ROUND", "SIGN", "SIN", "TAN", "LOG10", "LOG2", "LOG"}
-
-	str := strings.ToUpper(formula)
-	for _, v := range mathFormula {
-		str = strings.Replace(str, v, "", -1)
-	}
-	str = strings.Replace(str, "(", "", -1)
-	str = strings.Replace(str, ")", "", -1)
-
-	byteMap := make(map[string]string)
-	for i := 0; i < len(str); i++ {
-		byteInt := str[i]
-		if byteInt >= 65 && byteInt <= 90 {
-			byteStr := string(byteInt)
-			if _, ok := byteMap[byteStr]; !ok {
-				byteMap[byteStr] = byteStr
-			}
-		}
-	}
-	return byteMap
-}
-
-func ReplaceFormula(edbInfoIdArr []*EdbInfo, valArr map[int]float64, formulaMap map[string]string, formulaStr string, edbInfoIdBytes []string) string {
-	funMap := GetFormulaMap()
-	for k, v := range funMap {
-		formulaStr = strings.Replace(formulaStr, k, v, -1)
-	}
-
-	replaceCount := 0
-	for dk, dv := range edbInfoIdArr {
-		if dk == 0 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 1 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 2 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 3 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 4 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 5 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 6 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 7 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 8 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-	}
-	for k, v := range funMap {
-		formulaStr = strings.Replace(formulaStr, v, k, -1)
-	}
-	if replaceCount == len(formulaMap) {
-		return formulaStr
-	} else {
-		return ""
-	}
-}
-
-func GetFormulaMap() map[string]string {
-	funMap := make(map[string]string)
-	funMap["MAX"] = "[@@]"
-	funMap["MIN"] = "[@!]"
-	funMap["ABS"] = "[@#]"
-	funMap["CEIL"] = "[@$]"
-	funMap["COS"] = "[@%]"
-	funMap["FLOOR"] = "[@^]"
-	funMap["MOD"] = "[@&]"
-	funMap["POW"] = "[@*]"
-	funMap["ROUND"] = "[@(]"
-	return funMap
-}
-
-func Calculate(edbInfoIdArr []*EdbInfo, edbInfoId int, edbCode, formulaStr string, edbInfoIdBytes []string) (err error) {
-	defer func() {
-		if err != nil {
-			utils.FileLog.Info("Calculate Err:%s" + err.Error())
-		}
-	}()
-	saveDataMap := make(map[string]map[int]float64)
-	for _, v := range edbInfoIdArr {
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, v.EdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, v.Source, 1)
-		if err != nil {
-			return err
-		}
-		dataMap := make(map[string]float64)
-		for _, dv := range dataList {
-			if val, ok := saveDataMap[dv.DataTime]; ok {
-				if _, ok := val[v.EdbInfoId]; !ok {
-					val[v.EdbInfoId] = dv.Value
-				}
-			} else {
-				temp := make(map[int]float64)
-				temp[v.EdbInfoId] = dv.Value
-				saveDataMap[dv.DataTime] = temp
-			}
-		}
-		item := new(CalculateItems)
-		item.EdbInfoId = v.EdbInfoId
-		item.DataMap = dataMap
-	}
-	formulaMap := CheckFormula(formulaStr)
-	addSql := ` INSERT INTO edb_data_calculate(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	var isAdd bool
-
-	for sk, sv := range saveDataMap {
-		formulaStr = strings.ToUpper(formulaStr)
-		formulaFormStr := ReplaceFormula(edbInfoIdArr, sv, formulaMap, formulaStr, edbInfoIdBytes)
-		if formulaStr == "" {
-			return
-		}
-		if formulaFormStr != "" {
-			utils.FileLog.Info("formulaFormStr:%s", formulaFormStr)
-			expression := formula.NewExpression(formulaFormStr)
-			calResult, err := expression.Evaluate()
-			if err != nil {
-				err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-			calVal, err := calResult.Float64()
-			if err != nil {
-				err = errors.New("计算失败:获取计算值失败 Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-
-			//需要存入的数据
-			{
-				dataTime, _ := time.Parse(utils.FormatDate, sk)
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				addSql += "("
-				addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + sk + "'" + "," + utils.SubFloatToString(calVal, 4) + "," + "'" + nowStr + "'" +
-					"," + "'" + nowStr + "'" + "," + "1"
-				addSql += "," + "'" + timeStr + "'"
-				addSql += "),"
-				isAdd = true
-			}
-		} else {
-			fmt.Println("formulaFormStr is empty")
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		AddEdbDataCalculateBySql(addSql)
-		if err != nil {
-			fmt.Println("AddEdbDataCalculate Err:" + err.Error())
-			return err
-		}
-	}
-	return
-}

+ 0 - 591
models/data_manage/edb_info_calculate_bp.go

@@ -1,591 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateBp struct {
-	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
-	EdbInfoId            int       `description:"指标id"`
-	EdbCode              string    `description:"指标编码"`
-	FromEdbInfoId        int       `description:"计算指标id"`
-	FromEdbCode          string    `description:"计算指标编码"`
-	FromEdbName          string    `description:"计算指标名称"`
-	FromSource           int       `description:"计算指标来源"`
-	FromSourceName       string    `description:"计算指标来源名称"`
-	FromTag              string    `description:"来源指标标签"`
-	Sort                 int       `description:"计算指标名称排序"`
-	CreateTime           time.Time `description:"创建时间"`
-	ModifyTime           time.Time `description:"修改时间"`
-}
-
-//变频
-func AddCalculateBp(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateBp")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateBp,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_BP
-		edbInfo.SourceName = "变频"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_BP)
-		fmt.Println("dataTableName:"+dataTableName)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-		if err!=nil {
-			return 0, err
-		}
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println("edbInfoIdStr:" + edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	fmt.Println("dataLen:", dataLen)
-
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-		var day int
-		var preItem *EdbInfoSearchData
-		var preDate time.Time
-		if i == 0 {
-			day = int(time.Now().Sub(currentDate).Hours() / float64(24))
-			preDate = time.Now()
-		} else {
-			j := i - 1
-			if j < dataLen {
-				preItem = dataList[j]
-				preDate, _ = time.Parse(utils.FormatDate, preItem.DataTime)
-				day = int(preDate.Sub(currentDate).Hours() / float64(24))
-				utils.FileLog.Info("preItem.DataTime:" + preItem.DataTime + ";currentItem.DataTime" + currentItem.DataTime)
-			}
-		}
-		for k := 0; k <= day; k++ {
-			needDay := preDate.AddDate(0, 0, -k)
-			needDayStr := needDay.Format(utils.FormatDate)
-			existKey := edbCode + needDayStr
-			if _, ok := existMap[existKey]; !ok {
-				timestamp := needDay.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				valStr := decimal.NewFromFloat(currentItem.Value).String()
-				addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
-				isAdd = true
-			}
-			existMap[existKey] = needDayStr
-		}
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
-			isAdd = true
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//环比值
-func EditCalculateBp(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 {
-		//删除指标关联计算指标
-		//sql := ` DELETE FROM edb_info_calculate_bp WHERE edb_info_id = ? `
-		//_, err = o.Raw(sql, edbInfoId).Exec()
-		//if err != nil {
-		//	return
-		//}
-
-		//calculateItem := new(EdbInfoCalculateHbz)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return
-		//}
-
-		//删除,计算指标关联的,基础指标的关联关系
-		sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			err = errors.New("删除计算指标关联关系失败,Err:" + err.Error())
-			return
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_bp WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_BP
-			calculateMappingItem.SourceName = "变频"
-			o.Insert(calculateMappingItem)
-		}
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-		fmt.Println("edbInfoIdStr:" + edbInfoIdStr)
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		existMap := make(map[string]string)
-		dataLen := len(dataList)
-		for i := 0; i < dataLen; i++ {
-			//当期
-			currentItem := dataList[i]
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			var day int
-			var preItem *EdbInfoSearchData
-			var preDate time.Time
-			if i == 0 {
-				day = int(time.Now().Sub(currentDate).Hours() / float64(24))
-				preDate = time.Now()
-			} else {
-				j := i + 1
-				if j < dataLen {
-					preItem = dataList[j]
-					preDate, _ = time.Parse(utils.FormatDate, preItem.DataTime)
-					day = int(currentDate.Sub(preDate).Hours() / float64(24))
-				}
-			}
-			for k := 0; k <= day; k++ {
-				needDay := preDate.AddDate(0, 0, -k)
-				needDayStr := needDay.Format(utils.FormatDate)
-				existKey := edbCode + needDayStr
-				if _, ok := existMap[existKey]; !ok {
-					timestamp := needDay.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					valStr := decimal.NewFromFloat(currentItem.Value).String()
-					addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
-				}
-				existMap[existKey] = needDayStr
-			}
-			existKey := edbCode + currentItem.DataTime
-			if _, ok := existMap[existKey]; !ok {
-				currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				valStr := decimal.NewFromFloat(currentItem.Value).String()
-				addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
-			}
-			existMap[existKey] = currentItem.DataTime
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//变频
-func RefreshCalculateBp(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-		var day int
-		var preItem *EdbInfoSearchData
-		var preDate time.Time
-		if i == 0 {
-			day = int(time.Now().Sub(currentDate).Hours() / float64(24))
-			preDate = time.Now()
-		} else {
-			j := i + 1
-			if j < dataLen {
-				preItem = dataList[j]
-				preDate, _ = time.Parse(utils.FormatDate, preItem.DataTime)
-				day = int(currentDate.Sub(preDate).Hours() / float64(24))
-			}
-		}
-		for k := 0; k <= day; k++ {
-			needDay := preDate.AddDate(0, 0, -k)
-			needDayStr := needDay.Format(utils.FormatDate)
-			existKey := edbCode + needDayStr
-			if _, ok := existMap[existKey]; !ok {
-				timestamp := needDay.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				valStr := decimal.NewFromFloat(currentItem.Value).String()
-				addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
-			}
-			existMap[existKey] = needDayStr
-		}
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateBpDetail struct {
-	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
-	EdbInfoId            int       `description:"指标id"`
-	EdbCode              string    `description:"指标编码"`
-	FromEdbInfoId        int       `description:"计算指标id"`
-	FromEdbCode          string    `description:"计算指标编码"`
-	FromEdbName          string    `description:"计算指标名称"`
-	FromSource           int       `description:"计算指标来源"`
-	FromSourceName       string    `description:"计算指标来源名称"`
-	FromTag              string    `description:"来源指标标签"`
-	Sort                 int       `description:"计算指标名称排序"`
-	CreateTime           time.Time `description:"创建时间"`
-	ModifyTime           time.Time `description:"修改时间"`
-	StartDate            string    `description:"开始日期"`
-	EndDate              string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateBpDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-//刷新所有变频数据
-func RefreshAllCalculateBp(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	fmt.Println("existDataMap:", existDataMap)
-	addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		//当期
-		currentItem := dataList[i]
-		currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-		var day int
-		var preItem *EdbInfoSearchData
-		var preDate time.Time
-		if i == 0 {
-			day = int(time.Now().Sub(currentDate).Hours() / float64(24))
-			preDate = time.Now()
-		} else {
-			j := i + 1
-			if j < dataLen {
-				preItem = dataList[j]
-				preDate, _ = time.Parse(utils.FormatDate, preItem.DataTime)
-				day = int(currentDate.Sub(preDate).Hours() / float64(24))
-			}
-		}
-		for k := 0; k <= day; k++ {
-			needDay := preDate.AddDate(0, 0, -k)
-			needDayStr := needDay.Format(utils.FormatDate)
-			existKey := edbCode + needDayStr
-			if _, ok := existMap[existKey]; !ok {
-				timestamp := needDay.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				valStr := decimal.NewFromFloat(currentItem.Value).String()
-				if existVal, ok := existDataMap[needDayStr]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
-				} else {
-					if existVal != valStr {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, valStr, edbInfoId, needDay).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-			existMap[existKey] = needDayStr
-		}
-		existKey := edbCode + currentItem.DataTime
-		if _, ok := existMap[existKey]; !ok {
-			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := decimal.NewFromFloat(currentItem.Value).String()
-			if existVal, ok := existDataMap[currentItem.DataTime]; !ok {
-				addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
-			} else {
-				if existVal != valStr {
-					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-					sql = fmt.Sprintf(sql, dataTableName)
-					_, err = o.Raw(sql, valStr, edbInfoId, currentItem.DataTime).Exec()
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-		existMap[existKey] = currentItem.DataTime
-	}
-
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 510
models/data_manage/edb_info_calculate_hbz.go

@@ -1,510 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-
-	"github.com/shopspring/decimal"
-)
-
-type EdbInfoCalculateHbz struct {
-	EdbInfoCalculateHbzId int       `orm:"column(edb_info_calculate_hbz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-}
-
-//环比值
-func AddCalculateHbz(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string, formulaInt int) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateHbz")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateHbz,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_HBZ
-		edbInfo.SourceName = "环比值"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_HBZ)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println("edbInfoIdStr:" + edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_hbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		j := i + formulaInt
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			fmt.Println("preItem.Value:", preItem.Value)
-			if currentItem != nil && preItem != nil && preItem.Value != 0 {
-				existKey := edbCode + currentItem.DataTime
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := HbzDiv(currentItem.Value, preItem.Value)
-					if val != "" {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-						isAdd = true
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//环比值,current:当期,pre:上期 公式: (当期-上期)/上期
-func HbzDiv(current, pre float64) string {
-	if pre == 0 {
-		return ""
-	}
-	currentVal := decimal.NewFromFloat(float64(current))
-	preVal := decimal.NewFromFloat(float64(pre))
-	val, _ := currentVal.Sub(preVal).Div(preVal).Float64()
-	valStr := utils.SubFloatToString(val, 4)
-	return valStr
-}
-
-//环比值
-func EditCalculateHbz(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string, formulaInt int, calculateFormula string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
- 			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, req.Formula, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 || strconv.Itoa(formulaInt) != calculateFormula {
-		//删除,计算指标关联的,基础指标的关联关系
-		if count <= 0 {
-			sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-			o.Raw(sql, edbInfoId).Exec()
-			//关联关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = edbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-				calculateMappingItem.FromSource = fromEdbInfo.Source
-				calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-				calculateMappingItem.FromTag = ""
-				calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_HBZ
-				calculateMappingItem.SourceName = "环比值"
-				o.Insert(calculateMappingItem)
-			}
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_hbz WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		addSql := ` INSERT INTO edb_data_calculate_hbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		existMap := make(map[string]string)
-		dataLen := len(dataList)
-		for i := 0; i < dataLen; i++ {
-			j := i + formulaInt
-			if j < dataLen {
-				//当期
-				currentItem := dataList[i]
-				preItem := dataList[j]
-				if currentItem != nil && preItem != nil {
-					existKey := edbCode + currentItem.DataTime
-					if _, ok := existMap[existKey]; !ok {
-						currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := HbzDiv(currentItem.Value, preItem.Value)
-						if val != "" {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						}
-					}
-					existMap[existKey] = currentItem.DataTime
-				}
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新环比值数据
-func RefreshCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	addSql := ` INSERT INTO edb_data_calculate_hbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	fmt.Println("dataLen:", dataLen)
-	for i := 0; i < dataLen; i++ {
-		j := i + 1
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			if currentItem != nil && preItem != nil {
-				existKey := edbCode + currentItem.DataTime
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := HbzDiv(currentItem.Value, preItem.Value)
-					if val != "" {
-						if existVal, findOk := existDataMap[currentItem.DataTime]; !findOk {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, currentItem.DataTime).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateHbzDetail struct {
-	EdbInfoCalculateTbzId int       `orm:"column(edb_info_calculate_tbz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-	StartDate             string    `description:"开始日期"`
-	EndDate               string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateHbzDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-//刷新所有环比值数据
-func RefreshAllCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string, formulaInt int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	addSql := ` INSERT INTO edb_data_calculate_hbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	fmt.Println("dataLen:", dataLen)
-	for i := 0; i < dataLen; i++ {
-		j := i + formulaInt
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			if currentItem != nil && preItem != nil {
-				existKey := edbCode + currentItem.DataTime
-
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := HbzDiv(currentItem.Value, preItem.Value)
-					if val != "" {
-						if existVal, findOk := existDataMap[currentItem.DataTime]; !findOk {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, currentItem.DataTime).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 527
models/data_manage/edb_info_calculate_hcz.go

@@ -1,527 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateHcz struct {
-	EdbInfoCalculateHczId int       `orm:"column(edb_info_calculate_hcz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-}
-
-//环差值
-func AddCalculateHcz(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string, formulaInt int) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateHcz")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateHcz,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_HCZ
-		edbInfo.SourceName = "环差值"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_HCZ)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println("edbInfoIdStr:" + edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_hcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	fmt.Println("dataLen:", dataLen)
-	for i := 0; i < dataLen; i++ {
-		j := i + formulaInt
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			if currentItem != nil && preItem != nil {
-				existKey := edbCode + currentItem.DataTime
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := ""
-					if preItem.Value == 0 {
-						val = "0"
-					} else {
-						val = HczDiv(currentItem.Value, preItem.Value)
-					}
-					if val != "" {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-						isAdd = true
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//环差值,current:当期,pre:上期 公式:当期-上期
-func HczDiv(current, pre float64) string {
-	if pre == 0 {
-		return ""
-	}
-	currentVal := decimal.NewFromFloat(current)
-	preVal := decimal.NewFromFloat(pre)
-	val, _ := currentVal.Sub(preVal).Float64()
-	valStr := utils.SubFloatToString(val, 4)
-	return valStr
-}
-
-//环比值
-func EditCalculateHcz(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string, formulaInt int, calculateFormula string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
- 			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, req.Formula, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-
-	if count <= 0 || strconv.Itoa(formulaInt) != calculateFormula {
-		//删除,计算指标关联的,基础指标的关联关系
-		if count<=0 {
-			sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-			_, err = o.Raw(sql, edbInfoId).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-			//关联关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = edbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-				calculateMappingItem.FromSource = fromEdbInfo.Source
-				calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-				calculateMappingItem.FromTag = ""
-				calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_HCZ
-				calculateMappingItem.SourceName = "环差值"
-				o.Insert(calculateMappingItem)
-			}
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_hcz WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-		fmt.Println("edbInfoIdStr:" + edbInfoIdStr)
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		var dateArr []string
-		dataMap := make(map[string]*EdbInfoSearchData)
-		for _, v := range dataList {
-			dateArr = append(dateArr, v.DataTime)
-			dataMap[v.DataTime] = v
-		}
-
-		addSql := ` INSERT INTO edb_data_calculate_hcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		existMap := make(map[string]string)
-		dataLen := len(dataList)
-		fmt.Println("dataLen:", dataLen)
-		for i := 0; i < dataLen; i++ {
-			j := i + formulaInt
-			if j < dataLen {
-				//当期
-				currentItem := dataList[i]
-				preItem := dataList[j]
-				if currentItem != nil && preItem != nil {
-					existKey := edbCode + currentItem.DataTime
-					if _, ok := existMap[existKey]; !ok {
-						currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := HczDiv(currentItem.Value, preItem.Value)
-						if val != "" {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						}
-					}
-					existMap[existKey] = currentItem.DataTime
-				}
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新环比值数据
-func RefreshCalculateHcz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	addSql := ` INSERT INTO edb_data_calculate_hcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		j := i + 1
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			if currentItem != nil && preItem != nil {
-				existKey := edbCode + currentItem.DataTime
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := HczDiv(currentItem.Value, preItem.Value)
-					if val != "" {
-						if existVal, findOk := existDataMap[currentItem.DataTime]; !findOk {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, currentItem.DataTime).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateHczDetail struct {
-	EdbInfoCalculateHczId int       `orm:"column(edb_info_calculate_hcz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-	StartDate             string    `description:"开始日期"`
-	EndDate               string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateHczDetail(edbInfoId int) (item *EdbInfoCalculateHczDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-//刷新所有环差值数据
-func RefreshAllCalculateHcz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string, formulaInt int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	fmt.Println("existDataMap:", existDataMap)
-	addSql := ` INSERT INTO edb_data_calculate_hcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	dataLen := len(dataList)
-	fmt.Println("dataLen:", dataLen)
-	for i := 0; i < dataLen; i++ {
-		j := i + formulaInt
-		if j < dataLen {
-			//当期
-			currentItem := dataList[i]
-			preItem := dataList[j]
-			if currentItem != nil && preItem != nil {
-				existKey := edbCode + currentItem.DataTime
-				if _, ok := existMap[existKey]; !ok {
-					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := HczDiv(currentItem.Value, preItem.Value)
-					if val != "" {
-						if existVal, findOk := existDataMap[currentItem.DataTime]; !findOk {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, val)
-							isAdd = true
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, currentItem.DataTime).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-					}
-				}
-				existMap[existKey] = currentItem.DataTime
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 892
models/data_manage/edb_info_calculate_ljztbpj.go

@@ -1,892 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"sort"
-	"strings"
-	"time"
-)
-
-// AddCalculateLjztbpj 新增累计值同比拼接数据
-func AddCalculateLjztbpj(req *EdbInfoCalculateBatchSaveReq, firstEdbInfo, secondEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateLjztbpj")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateLjztbpj,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	//待拼接指标map
-	pjDataMap := make(map[string]float64)
-
-	//拼接指标的日期切片数据
-	pjEdbDataTimeList := make([]string, 0)
-
-	//最近开始的时间
-	var lastDateTime time.Time
-	//获取待拼接指标
-	{
-		var condition string
-		var pars []interface{}
-
-		//获取待拼接指标最近的个12月31日有值的年份
-		condition += " AND data_time like ? AND edb_info_id=? "
-		pars = append(pars, "%12-31", firstEdbInfo.EdbInfoId)
-
-		lastEdbData, tmpErr := GetLastEdbData(condition, pars, firstEdbInfo.Source)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-		lastDateTime, _ = time.ParseInLocation(utils.FormatDate, lastEdbData.DataTime, time.Local)
-
-		//获取待拼接指标的数据列表
-		condition = ``
-		pars = make([]interface{}, 0)
-		condition += " AND data_time <= ? AND edb_info_id=? "
-		pars = append(pars, lastEdbData.DataTime, firstEdbInfo.EdbInfoId)
-
-		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, firstEdbInfo.Source, 0)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-
-		for _, v := range firstDataList {
-			pjDataMap[v.DataTime] = v.Value
-			pjEdbDataTimeList = append(pjEdbDataTimeList, v.DataTime)
-		}
-	}
-
-	var edbInfo *EdbInfo
-	if req.EdbInfoId <= 0 {
-		edbInfo = &EdbInfo{
-			SourceName:       "累计值同比拼接",
-			Source:           utils.DATA_SOURCE_CALCULATE_LJZTBPJ,
-			EdbCode:          edbCode,
-			EdbName:          req.EdbName,
-			EdbNameSource:    req.EdbName,
-			Frequency:        req.Frequency,
-			Unit:             req.Unit,
-			StartDate:        firstEdbInfo.StartDate,
-			EndDate:          firstEdbInfo.EndDate,
-			ClassifyId:       req.ClassifyId,
-			SysUserId:        sysUserId,
-			SysUserRealName:  sysUserRealName,
-			UniqueCode:       uniqueCode,
-			CreateTime:       time.Now(),
-			ModifyTime:       time.Now(),
-			CalculateFormula: lastDateTime.Format(utils.FormatDate),
-			EdbType:          2,
-		}
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-	} else {
-		edbInfoId = req.EdbInfoId
-		//查询
-		tmpEdbInfo, tmpErr := GetEdbInfoById(edbInfoId)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		tmpEdbInfo.EdbName = req.EdbName
-		tmpEdbInfo.ClassifyId = req.ClassifyId
-		tmpEdbInfo.Frequency = req.Frequency
-		tmpEdbInfo.Unit = req.Unit
-		tmpEdbInfo.CalculateFormula = req.Formula
-
-		edbInfo = tmpEdbInfo
-
-		//删除指标数据
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_LJZTBPJ)
-		fmt.Println("dataTableName:" + dataTableName)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-		if err != nil {
-			return 0, err
-		}
-
-		//删除指标关系
-		sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-	}
-
-	//关联关系
-
-	//拼接指标
-	{
-		calculateMappingItem := new(EdbInfoCalculateMapping)
-		calculateMappingItem.CreateTime = time.Now()
-		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
-		calculateMappingItem.EdbCode = edbCode
-		calculateMappingItem.EdbInfoId = edbInfoId
-		calculateMappingItem.FromEdbInfoId = firstEdbInfo.EdbInfoId
-		calculateMappingItem.FromEdbCode = firstEdbInfo.EdbCode
-		calculateMappingItem.FromEdbName = firstEdbInfo.EdbName
-		calculateMappingItem.FromSource = firstEdbInfo.Source
-		calculateMappingItem.FromSourceName = firstEdbInfo.SourceName
-		calculateMappingItem.FromTag = "A"
-		calculateMappingItem.Source = edbInfo.Source
-		calculateMappingItem.SourceName = edbInfo.SourceName
-		go o.Insert(calculateMappingItem)
-	}
-
-	//同比值指标
-	{
-		calculateMappingItem := new(EdbInfoCalculateMapping)
-		calculateMappingItem.CreateTime = time.Now()
-		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
-		calculateMappingItem.EdbCode = edbCode
-		calculateMappingItem.EdbInfoId = edbInfoId
-		calculateMappingItem.FromEdbInfoId = secondEdbInfo.EdbInfoId
-		calculateMappingItem.FromEdbCode = secondEdbInfo.EdbCode
-		calculateMappingItem.FromEdbName = secondEdbInfo.EdbName
-		calculateMappingItem.FromSource = secondEdbInfo.Source
-		calculateMappingItem.FromSourceName = secondEdbInfo.SourceName
-		calculateMappingItem.FromTag = "B"
-		calculateMappingItem.Source = edbInfo.Source
-		calculateMappingItem.SourceName = edbInfo.SourceName
-		go o.Insert(calculateMappingItem)
-	}
-
-	//同比值指标map
-	tbzEdbDataMap := make(map[string]float64)
-
-	//同比值日期切片列表
-	tbzEdbDataTimeList := make([]string, 0)
-
-	//同比值指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time > ? AND edb_info_id = ? "
-		pars = append(pars, lastDateTime, secondEdbInfo.EdbInfoId)
-
-		//同比值指标的数据列表
-		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, secondEdbInfo.Source, 0)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-
-		for _, v := range secondDataList {
-			tbzEdbDataMap[v.DataTime] = v.Value
-			tbzEdbDataTimeList = append(tbzEdbDataTimeList, v.DataTime)
-		}
-	}
-
-	sort.Strings(tbzEdbDataTimeList)
-	for _, v := range tbzEdbDataTimeList {
-		tbzDataTime, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
-
-		//获取拼接指标上一年同一天的数据
-		var pjDataTime time.Time
-		if tbzDataTime.Month() == 2 {
-			pjDataTime = tbzDataTime.AddDate(0, -11, 0)
-			pjDataTime = time.Date(pjDataTime.Year(), pjDataTime.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 0, -1)
-		} else {
-			pjDataTime = tbzDataTime.AddDate(-1, 0, 0)
-		}
-
-		//如果存在数据,那么就去计算当前的数据
-		if pjDataValue, ok := pjDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
-			tbzDataValue := tbzEdbDataMap[v] //同比值
-			currValue := pjDataValue * (1 + tbzDataValue/100)
-
-			currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64()
-			//将计算后的数据存入待拼接指标map里面,以便后续计算
-			pjDataMap[v] = currValue
-
-			pjEdbDataTimeList = append(pjEdbDataTimeList, v)
-		}
-	}
-
-	addDataList := make([]*EdbDataCalculateLjztbpj, 0)
-
-	//日期排序下
-	sort.Strings(pjEdbDataTimeList)
-	//这么做的目的是为了让数据插入的时候,可以正序插入(业务上没啥卵用,就是为了让我看数据的时候舒服点,手动狗头-_-|)
-	for _, dataTime := range pjEdbDataTimeList {
-		if dataValue, ok := pjDataMap[dataTime]; ok {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, dataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataLjztbpj := &EdbDataCalculateLjztbpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       edbInfo.EdbCode,
-				DataTime:      dataTime,
-				Value:         dataValue,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataLjztbpj)
-		}
-	}
-
-	//数据入库
-	tmpAddDataList := make([]*EdbDataCalculateLjztbpj, 0)
-	for _, v := range addDataList {
-		tmpAddDataList = append(tmpAddDataList, v)
-
-		if len(tmpAddDataList) >= 200 {
-			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-			//重新初始化需要加入的数据切片
-			tmpAddDataList = make([]*EdbDataCalculateLjztbpj, 0)
-		}
-	}
-	//最后如果还有需要新增的数据,那么就统一入库
-	if len(tmpAddDataList) > 0 {
-		_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-	}
-
-	return
-}
-
-// EditCalculateLjztbpj 编辑累计值同比拼接数据
-func EditCalculateLjztbpj(req *EdbInfoCalculateBatchEditReq, nowEdbInfo, firstEdbInfo, secondEdbInfo *EdbInfo) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	sql := ``
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	//查询出所有的关联指标
-	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-
-	var existItemA, existItemB *EdbInfoCalculateMapping
-	for _, existItem := range existList {
-		if existItem.FromTag == "A" {
-			existItemA = existItem
-		} else if existItem.FromTag == "B" {
-			existItemB = existItem
-		}
-	}
-	// 原数据开始计算日期
-	startCalculationDate, _ := time.ParseInLocation(utils.FormatDate, nowEdbInfo.CalculateFormula, time.Local)
-
-	//待拼接指标map
-	pjDataMap := make(map[string]float64)     //需要入库的数据
-	nowEdbDataMap := make(map[string]float64) //当前指标的数据(已经在库里了,不需要重新)
-
-	//拼接指标的日期切片数据
-	pjEdbDataTimeList := make([]string, 0)
-
-	//最近开始的时间
-	lastDateTime := startCalculationDate
-
-	//待拼接指标数据
-	{
-		//如果拼接指标变更了,那么需要删除所有的指标进行重新拼接
-		if existItemA.FromEdbInfoId != firstEdbInfo.EdbInfoId {
-			//删除旧的指标数据
-			{
-				//删除之前的A指标关联关系
-				sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
-				_, err = o.Raw(sql, edbInfoId, existItemA.FromEdbInfoId).Exec()
-				if err != nil {
-					err = errors.New("删除拼接日期之前的指标关联关系失败,Err:" + err.Error())
-					return
-				}
-
-				//如果拼接指标变更了,那么需要删除所有的指标数据
-				tableName := GetEdbDataTableName(nowEdbInfo.Source)
-				sql = fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? `, tableName)
-
-				_, err = o.Raw(sql, edbInfoId).Exec()
-				if err != nil {
-					err = errors.New("删除所有的累计值同比拼接指标数据失败,Err:" + err.Error())
-					return
-				}
-			}
-
-			//添加新的指标关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = nowEdbInfo.EdbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = firstEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = firstEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = firstEdbInfo.EdbName
-				calculateMappingItem.FromSource = firstEdbInfo.Source
-				calculateMappingItem.FromSourceName = firstEdbInfo.SourceName
-				calculateMappingItem.FromTag = "A"
-				calculateMappingItem.Source = nowEdbInfo.Source
-				calculateMappingItem.SourceName = nowEdbInfo.SourceName
-				go o.Insert(calculateMappingItem)
-			}
-
-			var condition string
-			var pars []interface{}
-
-			//获取待拼接指标最近的个12月31日有值的年份
-			condition += " AND data_time like ? AND edb_info_id=? "
-			pars = append(pars, "%12-31", firstEdbInfo.EdbInfoId)
-
-			//获取最新的待拼接指标
-			lastEdbData, tmpErr := GetLastEdbData(condition, pars, firstEdbInfo.Source)
-			if tmpErr != nil {
-				return edbInfoId, tmpErr
-			}
-			lastDateTime, _ = time.ParseInLocation(utils.FormatDate, lastEdbData.DataTime, time.Local)
-
-			//获取待拼接指标的数据列表
-			condition = ``
-			pars = make([]interface{}, 0)
-			condition += " AND data_time <= ? AND edb_info_id=? "
-			pars = append(pars, lastEdbData.DataTime, firstEdbInfo.EdbInfoId)
-
-			firstDataList, tmpErr := GetEdbDataListAll(condition, pars, firstEdbInfo.Source, 0)
-			if tmpErr != nil {
-				return edbInfoId, tmpErr
-			}
-
-			for _, v := range firstDataList {
-				pjDataMap[v.DataTime] = v.Value
-				pjEdbDataTimeList = append(pjEdbDataTimeList, v.DataTime)
-
-				//将新的数据存入已入库指标map里面,以便后续计算
-				nowEdbDataMap[v.DataTime] = v.Value
-			}
-		} else {
-			// 获取当前指标的所有数据
-			var condition string
-			var pars []interface{}
-			condition += " AND edb_info_id=? and data_time <= ?"
-			pars = append(pars, nowEdbInfo.EdbInfoId, nowEdbInfo.CalculateFormula)
-
-			nowEdbDataList, tmpErr := GetEdbDataListAll(condition, pars, nowEdbInfo.Source, 0)
-			if tmpErr != nil {
-				return edbInfoId, tmpErr
-			}
-
-			for _, v := range nowEdbDataList {
-				nowEdbDataMap[v.DataTime] = v.Value
-				pjEdbDataTimeList = append(pjEdbDataTimeList, v.DataTime)
-			}
-		}
-	}
-
-	//同比值指标map
-	tbzEdbDataMap := make(map[string]float64)
-
-	//同比值日期切片列表
-	tbzEdbDataTimeList := make([]string, 0)
-
-	//同比值指标
-	{
-		if existItemB.FromEdbInfoId != secondEdbInfo.EdbInfoId {
-			//删除通过B指标生成的数据
-			{
-				//删除之前的B指标关联关系
-				sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
-				_, err = o.Raw(sql, edbInfoId, existItemB.FromEdbInfoId).Exec()
-				if err != nil {
-					err = errors.New("删除拼接日期之后的指标关联关系失败,Err:" + err.Error())
-					return
-				}
-
-				//如果同比值指标变更了,那么需要删除所有计算出来的指标数据
-				tableName := GetEdbDataTableName(nowEdbInfo.Source)
-				sql = fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time > ? `, tableName)
-
-				_, err = o.Raw(sql, edbInfoId, nowEdbInfo.CalculateFormula).Exec()
-				if err != nil {
-					err = errors.New("删除计算出来的累计值同比拼接指标数据失败,Err:" + err.Error())
-					return
-				}
-			}
-
-			//添加新的指标关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = nowEdbInfo.EdbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = secondEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = secondEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = secondEdbInfo.EdbName
-				calculateMappingItem.FromSource = secondEdbInfo.Source
-				calculateMappingItem.FromSourceName = secondEdbInfo.SourceName
-				calculateMappingItem.FromTag = "B"
-				calculateMappingItem.Source = nowEdbInfo.Source
-				calculateMappingItem.SourceName = nowEdbInfo.SourceName
-				go o.Insert(calculateMappingItem)
-			}
-		}
-
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time > ? AND edb_info_id = ? "
-		pars = append(pars, lastDateTime, secondEdbInfo.EdbInfoId)
-
-		//同比值指标的数据列表
-		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, secondEdbInfo.Source, 0)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-
-		for _, v := range secondDataList {
-			tbzEdbDataMap[v.DataTime] = v.Value
-			tbzEdbDataTimeList = append(tbzEdbDataTimeList, v.DataTime)
-		}
-	}
-
-	sort.Strings(tbzEdbDataTimeList)
-
-	// 遍历现有的数据,判断拼接指标中是否存在该日期数据,如果拼接指标无此数据,那么需要删除该日期数据(日期的判断:需要在开始计算日期之后)
-	removeDateList := make([]string, 0)
-	for nowEdbDate := range nowEdbDataMap {
-		nowEdbDateTime, _ := time.ParseInLocation(utils.FormatDate, nowEdbDate, time.Local)
-		//校验日期 需要 大于 拼接前日期
-		if startCalculationDate.Before(nowEdbDateTime) {
-			if _, ok := tbzEdbDataMap[nowEdbDate]; !ok {
-				// 同比指标中,不存在该日期数据,那么需要移除 现有数据 中该日期的数据
-				removeDateList = append(removeDateList, nowEdbDate)
-			}
-		}
-	}
-
-	//待修改的指标数据map(index:日期,value:值)
-	updateEdbDataMap := make(map[string]float64)
-	for _, v := range tbzEdbDataTimeList {
-		tbzDataTime, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
-
-		//获取拼接指标上一年同一天的数据
-		var pjDataTime time.Time
-		if tbzDataTime.Month() == 2 {
-			pjDataTime = tbzDataTime.AddDate(0, -11, 0)
-			pjDataTime = time.Date(pjDataTime.Year(), pjDataTime.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 0, -1)
-		} else {
-			pjDataTime = tbzDataTime.AddDate(-1, 0, 0)
-		}
-
-		//校验现有数据中,是否存在该日期的数据,如果存在的话,那么就要去校验 最新计算数据 与 现有数据 是否一致
-		if nowEdbDataValue, isHas := nowEdbDataMap[v]; isHas {
-			//获取去年今日的数据,获取到后,然后是去修改该日期的数据
-			if lastYearEdbDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
-				tbzDataValue := tbzEdbDataMap[v] //同比值
-				currValue := lastYearEdbDataValue * (1 + tbzDataValue/100)
-				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64() //保留4位小数
-				//如果计算出来的值与库里面的值不匹配,那么就去修改该值
-				if nowEdbDataValue != currValue {
-					//将计算后的数据存入待拼接指标map里面,以便后续计算
-					updateEdbDataMap[v] = currValue
-				}
-			}
-		} else {
-			//因为 现有数据中 不存在该日期数据,那么需要做新增数据处理
-
-			//如果去年今日存在该数据,那么就去计算当前的数据
-			if pjDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
-				tbzDataValue := tbzEdbDataMap[v] //同比值
-				currValue := pjDataValue * (1 + tbzDataValue/100)
-
-				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64()
-				//将计算后的数据存入已入库指标map里面,以便后续计算
-				nowEdbDataMap[v] = currValue
-
-				//将计算后的数据存入待拼接指标map里面,以便后续入库
-				pjDataMap[v] = currValue
-				pjEdbDataTimeList = append(pjEdbDataTimeList, v)
-			}
-		}
-	}
-
-	//新增的数据入库
-	{
-		addDataList := make([]*EdbDataCalculateLjztbpj, 0)
-		for dataTime, dataValue := range pjDataMap {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, dataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataLjztbpj := &EdbDataCalculateLjztbpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       nowEdbInfo.EdbCode,
-				DataTime:      dataTime,
-				Value:         dataValue,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataLjztbpj)
-		}
-
-		tmpAddDataList := make([]*EdbDataCalculateLjztbpj, 0)
-		for _, v := range addDataList {
-			tmpAddDataList = append(tmpAddDataList, v)
-
-			if len(tmpAddDataList) >= 200 {
-				_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-				if tmpErr != nil {
-					err = tmpErr
-					return
-				}
-				//重新初始化需要加入的数据切片
-				tmpAddDataList = make([]*EdbDataCalculateLjztbpj, 0)
-			}
-		}
-		//最后如果还有需要新增的数据,那么就统一入库
-		if len(tmpAddDataList) > 0 {
-			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-		}
-	}
-
-	//删除已经不存在的累计同比拼接指标数据(由于同比值当日的数据删除了)
-	{
-		if len(removeDateList) > 0 {
-			removeDateStr := strings.Join(removeDateList, `","`)
-			removeDateStr = `"` + removeDateStr + `"`
-			//如果拼接指标变更了,那么需要删除所有的指标数据
-			tableName := GetEdbDataTableName(nowEdbInfo.Source)
-			sql = fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
-
-			_, err = o.Raw(sql, edbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除不存在的累计值同比拼接指标数据失败,Err:" + err.Error())
-				return
-			}
-		}
-	}
-
-	//修改现有的数据中对应的值
-	{
-		tableName := GetEdbDataTableName(nowEdbInfo.Source)
-		for edbDate, edbDataValue := range updateEdbDataMap {
-			sql = fmt.Sprintf(` UPDATE  %s set value = %f,modify_time=now() WHERE edb_info_id = ? and data_time = %s `, tableName, edbDataValue, edbDate)
-
-			_, err = o.Raw(sql, edbInfoId).Exec()
-			if err != nil {
-				err = errors.New("更新现有的累计值同比拼接指标数据失败,Err:" + err.Error())
-				return
-			}
-		}
-	}
-
-	//修改指标信息
-	sql = ` UPDATE  edb_info SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?, 
-			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, lastDateTime.Format(utils.FormatDate), edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	return
-}
-
-// RefreshAllCalculateLjztbpj 刷新所有 累计值同比拼接 数据
-func RefreshAllCalculateLjztbpj(edbInfo *EdbInfo) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//查询当前指标现有的数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfo.EdbInfoId)
-
-	//所有的数据
-	dataList, err := GetAllEdbDataCalculateLjztbpjByEdbInfoId(edbInfo.EdbInfoId)
-	if err != nil {
-		return err
-	}
-
-	//待拼接指标map
-	pjDataMap := make(map[string]float64)     //需要入库的数据
-	nowEdbDataMap := make(map[string]float64) //当前指标的数据(已经在库里了,不需要重新)
-	//拼接指标的日期切片数据
-	pjEdbDataTimeList := make([]string, 0)
-
-	dataMap := make(map[string]*EdbDataCalculateLjztbpj)
-	for _, v := range dataList {
-		pjEdbDataTimeList = append(pjEdbDataTimeList, v.DataTime)
-		dataMap[v.DataTime] = v
-		nowEdbDataMap[v.DataTime] = v.Value
-	}
-
-	//查询关联指标信息
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfo.EdbInfoId)
-	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-
-	var existItemA, existItemB *EdbInfoCalculateMapping
-	for _, existItem := range existList {
-		if existItem.FromTag == "A" {
-			existItemA = existItem
-		} else if existItem.FromTag == "B" {
-			existItemB = existItem
-		}
-	}
-	// 原数据开始计算日期
-	startCalculationDate, _ := time.ParseInLocation(utils.FormatDate, edbInfo.CalculateFormula, time.Local)
-
-	//待拼接指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time <= ? AND edb_info_id=? "
-		pars = append(pars, startCalculationDate, existItemA.FromEdbInfoId)
-
-		//第一个指标的数据列表
-		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemA.FromSource, 0)
-		if tmpErr != nil {
-			return tmpErr
-		}
-
-		for _, v := range firstDataList {
-			//时间戳
-			if edbData, ok := dataMap[v.DataTime]; ok {
-				if edbData.Value != v.Value {
-					//更新指标数据
-					edbData.Value = v.Value
-					o.Update(edbData, "Value")
-
-					//将新的数据存入已入库指标map里面,以便后续计算
-					nowEdbDataMap[edbData.DataTime] = v.Value
-				}
-			}
-		}
-	}
-
-	//同比值指标map
-	tbzEdbDataMap := make(map[string]float64)
-
-	//同比值日期切片列表
-	tbzEdbDataTimeList := make([]string, 0)
-
-	//同比值指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time > ? AND edb_info_id = ? "
-		pars = append(pars, startCalculationDate, existItemB.FromEdbInfoId)
-
-		//第二个指标的数据列表
-		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemB.FromSource, 0)
-		if tmpErr != nil {
-			return tmpErr
-		}
-
-		for _, v := range secondDataList {
-			tbzEdbDataMap[v.DataTime] = v.Value
-			tbzEdbDataTimeList = append(tbzEdbDataTimeList, v.DataTime)
-		}
-	}
-
-	sort.Strings(tbzEdbDataTimeList)
-
-	// 遍历现有的数据,判断拼接指标中是否存在该日期数据,如果拼接指标无此数据,那么需要删除该日期数据(日期的判断:需要在开始计算日期之后)
-	removeDateList := make([]string, 0)
-	for nowEdbDate := range nowEdbDataMap {
-		nowEdbDateTime, _ := time.ParseInLocation(utils.FormatDate, nowEdbDate, time.Local)
-		//校验日期 需要 大于 拼接前日期
-		if startCalculationDate.Before(nowEdbDateTime) {
-			if _, ok := tbzEdbDataMap[nowEdbDate]; !ok {
-				// 同比指标中,不存在该日期数据,那么需要移除 现有数据 中该日期的数据
-				removeDateList = append(removeDateList, nowEdbDate)
-			}
-		}
-	}
-
-	//待修改的指标数据map(index:日期,value:值)
-	updateEdbDataMap := make(map[string]float64)
-	for _, v := range tbzEdbDataTimeList {
-		tbzDataTime, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
-
-		//获取拼接指标上一年同一天的数据
-		var pjDataTime time.Time
-		if tbzDataTime.Month() == 2 {
-			pjDataTime = tbzDataTime.AddDate(0, -11, 0)
-			pjDataTime = time.Date(pjDataTime.Year(), pjDataTime.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 0, -1)
-		} else {
-			pjDataTime = tbzDataTime.AddDate(-1, 0, 0)
-		}
-
-		//校验现有数据中,是否存在该日期的数据,如果存在的话,那么就要去校验 最新计算数据 与 现有数据 是否一致
-		if nowEdbDataValue, isHas := nowEdbDataMap[v]; isHas {
-			//获取去年今日的数据,获取到后,然后是去修改该日期的数据
-			if lastYearEdbDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
-
-				if v == "2021-08-31" {
-					fmt.Println("进来了")
-				}
-				tbzDataValue := tbzEdbDataMap[v] //同比值
-				currValue := lastYearEdbDataValue * (1 + tbzDataValue/100)
-				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64() //保留4位小数
-				//如果计算出来的值与库里面的值不匹配,那么就去修改该值
-				if nowEdbDataValue != currValue {
-					//将计算后的数据存入待拼接指标map里面,以便后续计算
-					updateEdbDataMap[v] = currValue
-				}
-			}
-		} else {
-			//因为 现有数据中 不存在该日期数据,那么需要做新增数据处理
-
-			//如果去年今日存在该数据,那么就去计算当前的数据
-			if pjDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
-				tbzDataValue := tbzEdbDataMap[v] //同比值
-				currValue := pjDataValue * (1 + tbzDataValue/100)
-
-				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64()
-				//将计算后的数据存入已入库指标map里面,以便后续计算
-				nowEdbDataMap[v] = currValue
-
-				//将计算后的数据存入待拼接指标map里面,以便后续入库
-				pjDataMap[v] = currValue
-				pjEdbDataTimeList = append(pjEdbDataTimeList, v)
-			}
-		}
-	}
-
-	//新增的数据入库
-	{
-		addDataList := make([]*EdbDataCalculateLjztbpj, 0)
-		for dataTime, dataValue := range pjDataMap {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, dataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataLjztbpj := &EdbDataCalculateLjztbpj{
-				EdbInfoId:     edbInfo.EdbInfoId,
-				EdbCode:       edbInfo.EdbCode,
-				DataTime:      dataTime,
-				Value:         dataValue,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataLjztbpj)
-		}
-
-		tmpAddDataList := make([]*EdbDataCalculateLjztbpj, 0)
-		for _, v := range addDataList {
-			tmpAddDataList = append(tmpAddDataList, v)
-
-			if len(tmpAddDataList) >= 200 {
-				_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-				if tmpErr != nil {
-					err = tmpErr
-					return
-				}
-				//重新初始化需要加入的数据切片
-				tmpAddDataList = make([]*EdbDataCalculateLjztbpj, 0)
-			}
-		}
-		//最后如果还有需要新增的数据,那么就统一入库
-		if len(tmpAddDataList) > 0 {
-			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-		}
-	}
-
-	//删除已经不存在的累计同比拼接指标数据(由于同比值当日的数据删除了)
-	{
-		if len(removeDateList) > 0 {
-			removeDateStr := strings.Join(removeDateList, `","`)
-			removeDateStr = `"` + removeDateStr + `"`
-			//如果拼接指标变更了,那么需要删除所有的指标数据
-			tableName := GetEdbDataTableName(edbInfo.Source)
-			sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
-
-			_, err = o.Raw(sql, edbInfo.EdbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除不存在的累计值同比拼接指标数据失败,Err:" + err.Error())
-				return
-			}
-		}
-	}
-
-	//修改现有的数据中对应的值
-	{
-		tableName := GetEdbDataTableName(edbInfo.Source)
-		for edbDate, edbDataValue := range updateEdbDataMap {
-			sql := fmt.Sprintf(` UPDATE  %s set value = ?,modify_time=now() WHERE edb_info_id = ? and data_time = ? `, tableName)
-
-			_, err = o.Raw(sql, edbDataValue, edbInfo.EdbInfoId, edbDate).Exec()
-			if err != nil {
-				err = errors.New("更新现有的累计值同比拼接指标数据失败,Err:" + err.Error())
-				return
-			}
-		}
-	}
-	return
-}

+ 0 - 785
models/data_manage/edb_info_calculate_ljzzy.go

@@ -1,785 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateLjzzy struct {
-	EdbInfoCalculateLjzzyId int       `orm:"column(edb_info_calculate_ljzzy_id);pk"`
-	EdbInfoId               int       `description:"指标id"`
-	EdbCode                 string    `description:"指标编码"`
-	FromEdbInfoId           int       `description:"计算指标id"`
-	FromEdbCode             string    `description:"计算指标编码"`
-	FromEdbName             string    `description:"计算指标名称"`
-	FromSource              int       `description:"计算指标来源"`
-	FromSourceName          string    `description:"计算指标来源名称"`
-	FromTag                 string    `description:"来源指标标签"`
-	Sort                    int       `description:"计算指标名称排序"`
-	CreateTime              time.Time `description:"创建时间"`
-	ModifyTime              time.Time `description:"修改时间"`
-}
-
-func AddEdbInfoCalculateLjzzyMulti(items []*EdbInfoCalculateLjzzy) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-//累计值转月
-func AddCalculateLjzzy(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_LJZZY
-		edbInfo.SourceName = "累计值转月值"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return int(newEdbInfoId), err
-		}
-		edbInfoId = int(newEdbInfoId)
-
-		//calculateItem := new(EdbInfoCalculateLjzzy)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return edbInfoId, err
-		//}
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_LJZZY)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 1)
-	if err != nil {
-		return edbInfoId, err
-	}
-
-	yearMap := make(map[int]map[int]*EdbInfoSearchData)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		item := dataList[i]
-		//日其中获取年
-		itemDate, err := time.Parse(utils.FormatDate, item.DataTime)
-		if err != nil {
-			return edbInfoId, err
-		}
-		year := itemDate.Year()
-		month := int(itemDate.Month())
-		if monthMap, yok := yearMap[year]; yok {
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		} else {
-			monthMap = make(map[int]*EdbInfoSearchData)
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		}
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_ljzzy(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for yk, yv := range yearMap {
-		_, oneMonthOk := yv[1]
-		_, twoMonthOk := yv[2]
-		if !oneMonthOk && !twoMonthOk {
-			continue
-		}
-		for i := 1; i <= 12; i++ {
-			fmt.Println(yk, i, yv[i])
-			dataCurrentItem := yv[i]
-			fmt.Println("i:", i, yk, dataCurrentItem)
-			var date string
-			var val float64
-			if i == 1 || i == 2 {
-				if _, mok := yv[1]; mok { //1月有值
-					if i == 1 {
-						date = dataCurrentItem.DataTime
-						val, _ = decimal.NewFromFloat(dataCurrentItem.Value).Float64() //a.Div(b).Float64()
-					}
-					if i == 2 {
-						dataOneItem := yv[1]
-						if dataCurrentItem != nil {
-							date = dataCurrentItem.DataTime
-							twoMonth := decimal.NewFromFloat(dataCurrentItem.Value)
-							oneMonth := decimal.NewFromFloat(dataOneItem.Value)
-							val, _ = twoMonth.Sub(oneMonth).Float64()
-						} else {
-							continue
-						}
-					}
-				} else { //1月无值
-					dataTwoItem := yv[2]
-					if i == 1 {
-						date = strconv.Itoa(yk) + "-01-31"
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-					if i == 2 {
-						date = dataCurrentItem.DataTime
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-				}
-			} else {
-				dataPreItem := yv[i-1]
-				if dataCurrentItem != nil && dataPreItem != nil {
-					date = dataCurrentItem.DataTime
-					//val, _ = decimal.NewFromFloat(dataCurrentItem.Value).Sub(decimal.NewFromFloat(dataPreItem.Value)).Float64()
-					a := decimal.NewFromFloat(dataCurrentItem.Value)
-					b := decimal.NewFromFloat(dataPreItem.Value)
-					val, _ = a.Sub(b).Float64()
-				}
-			}
-
-			if date != "" {
-				dataTime, _ := time.Parse(utils.FormatDate, date)
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-
-				if _, ok := existMap[edbCode+date]; !ok {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, date, timeStr, utils.SubFloatToString(val, 4))
-					isAdd = true
-				}
-				existMap[edbCode+date] = date
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//修改累计值转月
-func EditCalculateLjzzy(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-              edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 {
-		//删除指标关联计算指标
-		//sql := ` DELETE FROM edb_info_calculate_ljzzy WHERE edb_info_id = ? `
-		//_, err = o.Raw(sql, edbInfoId).Exec()
-		//if err != nil {
-		//	return
-		//}
-
-		//calculateItem := new(EdbInfoCalculateLjzzy)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return
-		//}
-
-		//删除,计算指标关联的,基础指标的关联关系
-		sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-		o.Raw(sql, edbInfoId).Exec()
-
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_ljzzy WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_LJZZY
-			calculateMappingItem.SourceName = "累计值转月"
-			o.Insert(calculateMappingItem)
-		}
-
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 1)
-		if err != nil {
-			return edbInfoId, err
-		}
-
-		yearMap := make(map[int]map[int]*EdbInfoSearchData)
-		dataLen := len(dataList)
-		for i := 0; i < dataLen; i++ {
-			item := dataList[i]
-			//日其中获取年
-			itemDate, err := time.Parse(utils.FormatDate, item.DataTime)
-			if err != nil {
-				return edbInfoId, err
-			}
-			year := itemDate.Year()
-			month := int(itemDate.Month())
-			if monthMap, yok := yearMap[year]; yok {
-				monthMap[month] = item
-				yearMap[year] = monthMap
-			} else {
-				monthMap = make(map[int]*EdbInfoSearchData)
-				monthMap[month] = item
-				yearMap[year] = monthMap
-			}
-		}
-
-		addSql := ` INSERT INTO edb_data_calculate_ljzzy(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		var isAdd bool
-
-		for yk, yv := range yearMap {
-			_, oneMonthOk := yv[1]
-			_, twoMonthOk := yv[2]
-			if !oneMonthOk && !twoMonthOk {
-				continue
-			}
-			for i := 1; i <= 12; i++ {
-				fmt.Println(yk, i, yv[i])
-				dataCurrentItem := yv[i]
-				var date string
-				var val float64
-				if i == 1 || i == 2 {
-					if _, mok := yv[1]; mok { //1月有值
-						if i == 1 {
-							date = dataCurrentItem.DataTime
-							val, _ = decimal.NewFromFloat(dataCurrentItem.Value).Float64() //a.Div(b).Float64()
-						}
-						if i == 2 {
-							dataOneItem := yv[1]
-							date = dataCurrentItem.DataTime
-							twoMonth := decimal.NewFromFloat(dataCurrentItem.Value)
-							oneMonth := decimal.NewFromFloat(dataOneItem.Value)
-							val, _ = twoMonth.Sub(oneMonth).Float64()
-						}
-					} else { //1月无值
-						dataTwoItem := yv[2]
-						if i == 1 {
-							date = strconv.Itoa(yk) + "-01-31"
-							a := decimal.NewFromFloat(dataTwoItem.Value)
-							b := decimal.NewFromFloat(2.0)
-							val, _ = a.Div(b).Float64()
-						}
-						if i == 2 {
-							date = dataCurrentItem.DataTime
-							a := decimal.NewFromFloat(dataTwoItem.Value)
-							b := decimal.NewFromFloat(2.0)
-							val, _ = a.Div(b).Float64()
-						}
-					}
-				} else {
-					dataPreItem := yv[i-1]
-					if dataCurrentItem != nil && dataPreItem != nil {
-						date = dataCurrentItem.DataTime
-						//val = dataCurrentItem.Value - dataPreItem.Value
-						a := decimal.NewFromFloat(dataCurrentItem.Value)
-						b := decimal.NewFromFloat(dataPreItem.Value)
-						val, _ = a.Sub(b).Float64()
-					}
-				}
-				if date != "" {
-					dataTime, _ := time.Parse(utils.FormatDate, date)
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-
-					addSql += "("
-					addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + date + "'" + "," + utils.SubFloatToString(val, 4) + "," + "'" + nowStr + "'" +
-						"," + "'" + nowStr + "'" + "," + "1"
-					addSql += "," + "'" + timeStr + "'"
-					addSql += "),"
-					isAdd = true
-				}
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新累计值转月值数据
-func RefreshCalculateLjzzy(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 1)
-	if err != nil {
-		return err
-	}
-
-	yearMap := make(map[int]map[int]*EdbInfoSearchData)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		item := dataList[i]
-		//日其中获取年
-		itemDate, err := time.Parse(utils.FormatDate, item.DataTime)
-		if err != nil {
-			return err
-		}
-		year := itemDate.Year()
-		month := int(itemDate.Month())
-		if monthMap, yok := yearMap[year]; yok {
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		} else {
-			monthMap = make(map[int]*EdbInfoSearchData)
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		}
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_ljzzy(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	var isAdd bool
-
-	for yk, yv := range yearMap {
-		_, oneMonthOk := yv[1]
-		_, twoMonthOk := yv[2]
-		if !oneMonthOk && !twoMonthOk {
-			continue
-		}
-		for i := 1; i <= 12; i++ {
-			fmt.Println(yk, i, yv[i])
-			dataCurrentItem := yv[i]
-			var date string
-			var val float64
-			if i == 1 || i == 2 {
-				if _, mok := yv[1]; mok { //1月有值
-					if i == 1 {
-						date = dataCurrentItem.DataTime
-						val, _ = decimal.NewFromFloat(dataCurrentItem.Value).Float64() //a.Div(b).Float64()
-					}
-					if i == 2 {
-						dataOneItem := yv[1]
-						date = dataCurrentItem.DataTime
-						twoMonth := decimal.NewFromFloat(dataCurrentItem.Value)
-						oneMonth := decimal.NewFromFloat(dataOneItem.Value)
-						val, _ = twoMonth.Sub(oneMonth).Float64()
-					}
-				} else { //1月无值
-					dataTwoItem := yv[2]
-					if i == 1 {
-						date = strconv.Itoa(yk) + "-01-31"
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-					if i == 2 {
-						date = dataCurrentItem.DataTime
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-				}
-			} else {
-				dataPreItem := yv[i-1]
-				if dataCurrentItem != nil && dataPreItem != nil {
-					date = dataCurrentItem.DataTime
-					//val =  dataCurrentItem.Value - dataPreItem.Value
-					a := decimal.NewFromFloat(dataCurrentItem.Value)
-					b := decimal.NewFromFloat(dataPreItem.Value)
-					val, _ = a.Sub(b).Float64()
-				}
-			}
-			if date != "" {
-				//判断数据是否存在
-				count, err := GetEdbDataCalculateLjzzyByCodeAndDate(edbCode, date)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
-				}
-				if count <= 0 {
-					dataTime, _ := time.Parse(utils.FormatDate, date)
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-
-					addSql += "("
-					addSql += edbInfoIdStr + "," + "'" + edbCode + "'" + "," + "'" + date + "'" + "," + utils.SubFloatToString(val, 4) + "," + "'" + nowStr + "'" +
-						"," + "'" + nowStr + "'" + "," + "1"
-					addSql += "," + "'" + timeStr + "'"
-					addSql += "),"
-					isAdd = true
-				} else {
-					valStr := utils.SubFloatToString(val, 4)
-					err = ModifyEdbDataCalculateLjzzy(int64(edbInfoId), date, valStr)
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateLjzzyDetail struct {
-	EdbInfoCalculateLjzzyId int       `orm:"column(edb_info_calculate_ljzzy_id);pk"`
-	EdbInfoId               int       `description:"指标id"`
-	EdbCode                 string    `description:"指标编码"`
-	FromEdbInfoId           int       `description:"计算指标id"`
-	FromEdbCode             string    `description:"计算指标编码"`
-	FromEdbName             string    `description:"计算指标名称"`
-	FromSource              int       `description:"计算指标来源"`
-	FromSourceName          string    `description:"计算指标来源名称"`
-	FromTag                 string    `description:"来源指标标签"`
-	Sort                    int       `description:"计算指标名称排序"`
-	CreateTime              time.Time `description:"创建时间"`
-	ModifyTime              time.Time `description:"修改时间"`
-	StartDate               string    `description:"开始日期"`
-	EndDate                 string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateLjzzyDetail(edbInfoId int) (item *EdbInfoCalculateLjzzyDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-func GetEdbDataCalculateLjzzyByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate_ljzzy WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataCalculateLjzzy(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_calculate_ljzzy SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新全部数据
-func RefreshAllCalculateLjzzy(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 1)
-	if err != nil {
-		return err
-	}
-
-	yearMap := make(map[int]map[int]*EdbInfoSearchData)
-	dataLen := len(dataList)
-	for i := 0; i < dataLen; i++ {
-		item := dataList[i]
-		//日其中获取年
-		itemDate, err := time.Parse(utils.FormatDate, item.DataTime)
-		if err != nil {
-			return err
-		}
-		year := itemDate.Year()
-		month := int(itemDate.Month())
-		if monthMap, yok := yearMap[year]; yok {
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		} else {
-			monthMap = make(map[int]*EdbInfoSearchData)
-			monthMap[month] = item
-			yearMap[year] = monthMap
-		}
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_ljzzy(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	dataMap := make(map[string]string)
-	for _, v := range existDataList {
-		dataMap[v.DataTime] = v.Value
-	}
-	existDataMap := make(map[string]string)
-	for yk, yv := range yearMap {
-		_, oneMonthOk := yv[1]
-		_, twoMonthOk := yv[2]
-		if !oneMonthOk && !twoMonthOk {
-			continue
-		}
-		for i := 1; i <= 12; i++ {
-			fmt.Println(yk, i, yv[i])
-			dataCurrentItem := yv[i]
-			var date string
-			var val float64
-			if i == 1 || i == 2 {
-				if _, mok := yv[1]; mok { //1月有值
-					if i == 1 {
-						date = dataCurrentItem.DataTime
-						val, _ = decimal.NewFromFloat(dataCurrentItem.Value).Float64() //a.Div(b).Float64()
-					}
-					if i == 2 {
-						dataOneItem := yv[1]
-						date = dataCurrentItem.DataTime
-						twoMonth := decimal.NewFromFloat(dataCurrentItem.Value)
-						oneMonth := decimal.NewFromFloat(dataOneItem.Value)
-						val, _ = twoMonth.Sub(oneMonth).Float64()
-					}
-				} else { //1月无值
-					dataTwoItem := yv[2]
-					if i == 1 {
-						date = strconv.Itoa(yk) + "-01-31"
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-					if i == 2 {
-						date = dataCurrentItem.DataTime
-						a := decimal.NewFromFloat(dataTwoItem.Value)
-						b := decimal.NewFromFloat(2.0)
-						val, _ = a.Div(b).Float64()
-					}
-				}
-			} else {
-				dataPreItem := yv[i-1]
-				if dataCurrentItem != nil && dataPreItem != nil {
-					date = dataCurrentItem.DataTime
-					//val =  dataCurrentItem.Value - dataPreItem.Value
-					a := decimal.NewFromFloat(dataCurrentItem.Value)
-					b := decimal.NewFromFloat(dataPreItem.Value)
-					val, _ = a.Sub(b).Float64()
-				}
-			}
-			if date != "" {
-				saveValue := utils.SubFloatToString(val, 4)
-				//判断数据是否存在
-				if existVal, ok := dataMap[date]; !ok {
-					dataTime, _ := time.Parse(utils.FormatDate, date)
-					timestamp := dataTime.UnixNano() / 1e6
-					timeStr := fmt.Sprintf("%d", timestamp)
-					if _, existOk := existDataMap[date]; !existOk {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, date, timeStr, saveValue)
-						isAdd = true
-					}
-					existDataMap[date] = date
-				} else {
-					if existVal != saveValue {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, saveValue, edbInfoId, date).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			fmt.Println("RefreshAllCalculateLjzzy add Err", err.Error())
-			return
-		}
-	}
-	return
-}

+ 0 - 71
models/data_manage/edb_info_calculate_mapping.go

@@ -1,71 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-//Seal 计算指标于基础指标,关系表
-type EdbInfoCalculateMapping struct {
-	EdbInfoCalculateMappingId int       `orm:"column(edb_info_calculate_mapping_id);pk"`
-	EdbInfoId                 int       `description:"计算指标id"`
-	Source                    int       `description:"计算指标来源"`
-	SourceName                string    `description:"计算指标来源名称"`
-	EdbCode                   string    `description:"计算指标编码"`
-	FromEdbInfoId             int       `description:"基础指标id"`
-	FromEdbCode               string    `description:"基础指标编码"`
-	FromEdbName               string    `description:"基础指标名称"`
-	FromSource                int       `description:"基础指标来源"`
-	FromSourceName            string    `description:"基础指标来源名称"`
-	FromTag                   string    `description:"来源指标标签"`
-	Sort                      int       `description:"计算指标名称排序"`
-	CreateTime                time.Time `description:"创建时间"`
-	ModifyTime                time.Time `description:"修改时间"`
-}
-
-func AddEdbInfoCalculateMappingMulti(items []*EdbInfoCalculateMapping) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func GetEdbInfoCalculateMappingCount(edbInfoId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE from_edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&count)
-	return
-}
-
-type EdbInfoCalculateMappingView struct {
-	EdbInfoCalculateMappingId int       `orm:"column(edb_info_calculate_mapping_id);pk"`
-	EdbInfoId                 int       `description:"计算指标id"`
-	Source                    int       `description:"计算指标来源"`
-	SourceName                string    `description:"计算指标来源名称"`
-	EdbCode                   string    `description:"计算指标编码"`
-	FromEdbInfoId             int       `description:"基础指标id"`
-	FromEdbCode               string    `description:"基础指标编码"`
-	FromEdbName               string    `description:"基础指标名称"`
-	FromSource                int       `description:"基础指标来源"`
-	FromSourceName            string    `description:"基础指标来源名称"`
-	FromTag                   string    `description:"来源指标标签"`
-	Sort                      int       `description:"计算指标名称排序"`
-	CreateTime                time.Time `description:"创建时间"`
-	ModifyTime                time.Time `description:"修改时间"`
-	StartDate                 string    `description:"开始日期"`
-	EndDate                   string    `description:"结束日期"`
-	CalculateFormula          string    `description:"N值"`
-	MoveType                  int       `description:"移动方式:1:领先(默认),2:滞后"`
-	MoveFrequency             string    `description:"移动频度"`
-}
-
-func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}

+ 0 - 617
models/data_manage/edb_info_calculate_nszydpjjs.go

@@ -1,617 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateNszydpjjs struct {
-	EdbInfoCalculateNszydpjjsId int       `orm:"column(edb_info_calculate_nszydpjjs_id);pk"`
-	EdbInfoId                   int       `description:"指标id"`
-	EdbCode                     string    `description:"指标编码"`
-	FromEdbInfoId               int       `description:"计算指标id"`
-	FromEdbCode                 string    `description:"计算指标编码"`
-	FromEdbName                 string    `description:"计算指标名称"`
-	FromSource                  int       `description:"计算指标来源"`
-	FromSourceName              string    `description:"计算指标来源名称"`
-	FromTag                     string    `description:"来源指标标签"`
-	Sort                        int       `description:"计算指标名称排序"`
-	CreateTime                  time.Time `description:"创建时间"`
-	ModifyTime                  time.Time `description:"修改时间"`
-}
-
-//N数值移动平均计算
-func AddCalculateNszydpjjs(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string, formulaInt int) (edbInfoId int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_NSZYDPJJS
-		edbInfo.SourceName = "N数值移动平均计算"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-
-		//calculateItem := new(EdbInfoCalculateNszydpjjs)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return edbInfoId, err
-		//}
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_NSZYDPJJS)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_nszydpjjs(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	arrLen := len(dateArr)
-	for ak, av := range dateArr {
-		//处理第一个值
-		var valArr []float64
-		if findItem, ok := dataMap[av]; ok {
-			valArr = append(valArr, findItem.Value)
-		} else {
-			continue
-		}
-		if ak+1 != arrLen {
-			//处理除第一个值之外的N-1个值
-			for i := 1; i < formulaInt; i++ {
-				arrIndex := ak + i
-				if arrIndex >= arrLen {
-					break
-				}
-				arrVal := dateArr[arrIndex]
-				if findItem, ok := dataMap[arrVal]; ok {
-					valArr = append(valArr, findItem.Value)
-				} else {
-					continue
-				}
-			}
-		}
-		valArrLen := len(valArr)
-		totalVal := decimal.NewFromFloat(0.00)
-		for _, v := range valArr {
-			newDecimal := decimal.NewFromFloat(v)
-			totalVal = totalVal.Add(newDecimal)
-		}
-		af := totalVal //decimal.NewFromFloat(totalVal)
-		bf := decimal.NewFromFloat(float64(valArrLen))
-		val, _ := af.Div(bf).Float64()
-		currentDate, err := time.Parse(utils.FormatDate, av)
-		if err != nil {
-			return edbInfoId, err
-		}
-
-		timestamp := currentDate.UnixNano() / 1e6
-		timestampStr := fmt.Sprintf("%d", timestamp)
-		valStr := utils.SubFloatToString(val, 4)
-		addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
-		isAdd = true
-	}
-
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-//修改N数值移动平均计算
-func EditCalculateNszydpjjs(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string, formulaInt int, oldCalculateFormula string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-              edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, req.Formula, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 || oldCalculateFormula != req.Formula {
-		//删除,计算指标关联的,基础指标的关联关系
-		sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_nszydpjjs WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_NSZYDPJJS
-			calculateMappingItem.SourceName = "N数值移动平均计算"
-			o.Insert(calculateMappingItem)
-		}
-
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		var dateArr []string
-		dataMap := make(map[string]*EdbInfoSearchData)
-		for _, v := range dataList {
-			dateArr = append(dateArr, v.DataTime)
-			dataMap[v.DataTime] = v
-		}
-
-		addSql := ` INSERT INTO edb_data_calculate_nszydpjjs(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-
-		arrLen := len(dateArr)
-		for ak, av := range dateArr {
-			//处理第一个值
-			var valArr []float64
-			if findItem, ok := dataMap[av]; ok {
-				valArr = append(valArr, findItem.Value)
-			} else {
-				continue
-			}
-			if ak+1 != arrLen {
-				//处理除第一个值之外的N-1个值
-				for i := 1; i < formulaInt; i++ {
-					arrIndex := ak + i
-					if arrIndex >= arrLen {
-						break
-					}
-					arrVal := dateArr[arrIndex]
-					if findItem, ok := dataMap[arrVal]; ok {
-						valArr = append(valArr, findItem.Value)
-					} else {
-						continue
-					}
-				}
-			}
-			valArrLen := len(valArr)
-			totalVal := decimal.NewFromFloat(0.00)
-			for _, v := range valArr {
-				newDecimal := decimal.NewFromFloat(v)
-				totalVal = totalVal.Add(newDecimal)
-			}
-			af := totalVal
-			bf := decimal.NewFromFloat(float64(valArrLen))
-			val, _ := af.Div(bf).Float64()
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return edbInfoId, err
-			}
-
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-
-			valStr := utils.SubFloatToString(val, 4)
-			addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
-			isAdd = true
-		}
-
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新N数值移动平均计算
-func RefreshCalculateNszydpjjs(edbInfoId, source, formulaInt int, fromEdbInfo *EdbInfo, edbCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("RefreshCalculateNszydpjjs Err:" + err.Error())
-			utils.FileLog.Info("RefreshCalculateNszydpjjs Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfoId)
-
-	existDataList, err := GetEdbDataListAll(condition, pars, source, 0)
-	if err != nil {
-		fmt.Println("existDataList GetEdbDataListAll Err:" + err.Error())
-		return err
-	}
-
-	existDataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v
-	}
-	startDate := time.Now().AddDate(-2, 0, 0).Format(utils.FormatDate)
-	//计算来源数据
-	var fromCondition string
-	var fromPars []interface{}
-	fromCondition += " AND edb_info_id=? "
-	fromPars = append(fromPars, fromEdbInfo.EdbInfoId)
-	fromCondition += " AND data_time>=? "
-	fromPars = append(fromPars, startDate)
-
-	fromDataList, err := GetEdbDataListAll(fromCondition, fromPars, fromEdbInfo.Source, 0)
-	if err != nil {
-		fmt.Println("from GetEdbDataListAll Err:" + err.Error())
-		return err
-	}
-
-	var fromDateArr []string
-	fromDataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range fromDataList {
-		fromDateArr = append(fromDateArr, v.DataTime)
-		fromDataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_nszydpjjs(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-
-	arrLen := len(fromDateArr)
-	for ak, av := range fromDateArr {
-		if _, existOk := existDataMap[av]; !existOk {
-			//处理第一个值
-			var valArr []float64
-			if findItem, ok := fromDataMap[av]; ok {
-				valArr = append(valArr, findItem.Value)
-			} else {
-				continue
-			}
-			if ak+1 != arrLen {
-				//处理除第一个值之外的N-1个值
-				for i := 1; i < formulaInt; i++ {
-					arrIndex := ak + i
-					if arrIndex >= arrLen {
-						break
-					}
-					arrVal := fromDateArr[arrIndex]
-					if findItem, ok := fromDataMap[arrVal]; ok {
-						valArr = append(valArr, findItem.Value)
-					} else {
-						continue
-					}
-				}
-			}
-			valArrLen := len(valArr)
-			//var totalVal float64
-			totalVal := decimal.NewFromFloat(0.00)
-			for _, v := range valArr {
-				newDecimal := decimal.NewFromFloat(v)
-				totalVal = totalVal.Add(newDecimal)
-			}
-			af := totalVal //decimal.NewFromFloat(totalVal)
-			bf := decimal.NewFromFloat(float64(valArrLen))
-			val, _ := af.Div(bf).Float64()
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			valStr := utils.SubFloatToString(val, 4)
-			addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
-			isAdd = true
-		}
-	}
-
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateNszydpjjsDetail struct {
-	EdbInfoCalculateNszydpjjsId int       `orm:"column(edb_info_calculate_nszydpjjs_id);pk"`
-	EdbInfoId                   int       `description:"指标id"`
-	EdbCode                     string    `description:"指标编码"`
-	FromEdbInfoId               int       `description:"计算指标id"`
-	FromEdbCode                 string    `description:"计算指标编码"`
-	FromEdbName                 string    `description:"计算指标名称"`
-	FromSource                  int       `description:"计算指标来源"`
-	FromSourceName              string    `description:"计算指标来源名称"`
-	FromTag                     string    `description:"来源指标标签"`
-	Sort                        int       `description:"计算指标名称排序"`
-	CreateTime                  time.Time `description:"创建时间"`
-	ModifyTime                  time.Time `description:"修改时间"`
-	StartDate                   string    `description:"开始日期"`
-	EndDate                     string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateNszydpjjsDetail(edbInfoId int) (item *EdbInfoCalculateNszydpjjsDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-//刷新全部N数值移动平均计算
-func RefreshAllCalculateNszydpjjs(edbInfoId, source, formulaInt int, fromEdbInfo *EdbInfo, edbCode, startDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("RefreshCalculateNszydpjjs Err:" + err.Error())
-			utils.FileLog.Info("RefreshCalculateNszydpjjs Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	fmt.Println(edbInfoIdStr)
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfoId)
-
-	existDataList, err := GetEdbDataListAll(condition, pars, source, 0)
-	if err != nil {
-		fmt.Println("existDataList GetEdbDataListAll Err:" + err.Error())
-		return err
-	}
-
-	existDataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v
-	}
-
-	//计算来源数据
-	var fromCondition string
-	var fromPars []interface{}
-	fromCondition += " AND edb_info_id=? "
-	fromPars = append(fromPars, fromEdbInfo.EdbInfoId)
-	fromCondition += " AND data_time>=? "
-	fromPars = append(fromPars, startDate)
-
-	fmt.Println("fromPars:", fromPars)
-	fromDataList, err := GetEdbDataListAll(fromCondition, fromPars, fromEdbInfo.Source, 0)
-	if err != nil {
-		fmt.Println("from GetEdbDataListAll Err:" + err.Error())
-		return err
-	}
-
-	var fromDateArr []string
-	fromDataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range fromDataList {
-		fromDateArr = append(fromDateArr, v.DataTime)
-		fromDataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_nszydpjjs(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	dataTableName := GetEdbDataTableName(source)
-	arrLen := len(fromDateArr)
-	existAddDataMap := make(map[string]string)
-	for ak, av := range fromDateArr {
-		//处理第一个值
-		var valArr []float64
-		if findItem, ok := fromDataMap[av]; ok {
-			valArr = append(valArr, findItem.Value)
-		} else {
-			continue
-		}
-		if ak+1 != arrLen {
-			//处理除第一个值之外的N-1个值
-			for i := 1; i < formulaInt; i++ {
-				arrIndex := ak + i
-				if arrIndex >= arrLen {
-					break
-				}
-				arrVal := fromDateArr[arrIndex]
-				if findItem, ok := fromDataMap[arrVal]; ok {
-					valArr = append(valArr, findItem.Value)
-				} else {
-					continue
-				}
-			}
-		}
-		valArrLen := len(valArr)
-		//var totalVal float64
-		totalVal := decimal.NewFromFloat(0.00)
-		for _, v := range valArr {
-			newDecimal := decimal.NewFromFloat(v)
-			totalVal = totalVal.Add(newDecimal)
-		}
-		af := totalVal //decimal.NewFromFloat(totalVal)
-		bf := decimal.NewFromFloat(float64(valArrLen))
-		val, _ := af.Div(bf).Float64()
-		valStr := utils.SubFloatToString(val, 4)
-
-		if existVal, existOk := existDataMap[av]; !existOk {
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			if _, existOk := existAddDataMap[av]; !existOk {
-				addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
-				isAdd = true
-			}
-			existAddDataMap[av] = av
-		} else {
-			saveValue := utils.SubFloatToString(existVal.Value, 30)
-			if saveValue != valStr {
-				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-				sql = fmt.Sprintf(sql, dataTableName)
-				_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		utils.FileLog.Info("addSql:" + addSql)
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 1031
models/data_manage/edb_info_calculate_tbz.go

@@ -1,1031 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateTbz struct {
-	EdbInfoCalculateTbzId int       `orm:"column(edb_info_calculate_tbz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-}
-
-//同比值
-func AddCalculateTbz(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateTbz")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_TBZ
-		edbInfo.SourceName = "同比值"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-
-		//calculateItem := new(EdbInfoCalculateTbz)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return edbInfoId, err
-		//}
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_TBZ)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_tbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, av := range dateArr {
-		//fmt.Println(ak, av)
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return edbInfoId, err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				if _, ok := existMap[edbCode+av]; !ok {
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := TbzDiv(currentItem.Value, findItem.Value)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-					utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-				}
-				existMap[edbCode+av] = av
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					nextDateDay := preDate
-					preDateDay := preDate
-					for i := 0; i <= 35; i++ {
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							if _, ok := existMap[edbCode+av]; !ok {
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existMap[edbCode+av] = av
-							break
-						} else {
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								if _, ok := existMap[edbCode+av]; !ok {
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TbzDiv(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existMap[edbCode+av] = av
-								break
-							}
-						}
-						nextDateDay = nextDateDay.AddDate(0, 0, 1)
-						preDateDay = preDateDay.AddDate(0, 0, -1)
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						if _, ok := existMap[edbCode+av]; !ok {
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-						}
-						existMap[edbCode+av] = av
-						break
-					}
-				} else {
-					nextDateDay := preDate
-					preDateDay := preDate
-
-					for i := 0; i < 35; i++ {
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							if _, ok := existMap[edbCode+av]; !ok {
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existMap[edbCode+av] = av
-							break
-						} else {
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								if _, ok := existMap[edbCode+av]; !ok {
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TbzDiv(currentItem.Value, findItem.Value)
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existMap[edbCode+av] = av
-								break
-							} else {
-								//fmt.Println("pre not find:", preDateStr, "i:", i)
-							}
-						}
-						nextDateDay = nextDateDay.AddDate(0, 0, 1)
-						preDateDay = preDateDay.AddDate(0, 0, -1)
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr string, value string) (addSql string) {
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	addSql += "("
-	addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
-		"," + "'" + nowStr + "'" + "," + "1"
-	addSql += "," + "'" + timestampStr + "'"
-	addSql += "),"
-	return
-}
-
-func TbzDiv(a, b float64) string {
-	var valStr string
-	if b != 0 {
-		af := decimal.NewFromFloat(float64(a))
-		bf := decimal.NewFromFloat(float64(b))
-		val, _ := af.Div(bf).Float64()
-		val = val - 1
-		valStr = utils.SubFloatToString(val, 4)
-	} else {
-		valStr = "0"
-	}
-	return valStr
-}
-
-//同比值
-func EditCalculateTbz(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 {
-		//删除指标关联计算指标
-		//sql := ` DELETE FROM edb_info_calculate_tbz WHERE edb_info_id = ? `
-		//_, err = o.Raw(sql, edbInfoId).Exec()
-		//if err != nil {
-		//	return
-		//}
-		//
-		//calculateItem := new(EdbInfoCalculateTbz)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return
-		//}
-
-		//删除,计算指标关联的,基础指标的关联关系
-		sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_tbz WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_TBZ
-			calculateMappingItem.SourceName = "同比值"
-			o.Insert(calculateMappingItem)
-		}
-
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		var dateArr []string
-		dataMap := make(map[string]*EdbInfoSearchData)
-		for _, v := range dataList {
-			dateArr = append(dateArr, v.DataTime)
-			dataMap[v.DataTime] = v
-		}
-
-		addSql := ` INSERT INTO edb_data_calculate_tbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		for _, av := range dateArr {
-			currentItem := dataMap[av]
-			if currentItem != nil {
-				//当前日期
-				currentDate, err := time.Parse(utils.FormatDate, av)
-				if err != nil {
-					return edbInfoId, err
-				}
-				//上一年的日期
-				preDate := currentDate.AddDate(-1, 0, 0)
-				preDateStr := preDate.Format(utils.FormatDate)
-				if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-					//dataTime, _ := time.Parse(utils.FormatDate, date)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := TbzDiv(currentItem.Value, findItem.Value)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-					utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-					continue
-				} else {
-					if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-						nextDateDay := preDate.AddDate(0, 1, 0)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-						preDateDay := preDate.AddDate(0, -1, 0)
-						preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-						for i := 0; i <= 6; i++ {
-							if i >= 1 {
-								nextDateDay = nextDateDay.AddDate(0, 0, i)
-								nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-								break
-							} else {
-								if i >= 1 {
-									preDateDay = preDate.AddDate(0, 0, -i)
-									preDateDayStr = nextDateDay.Format(utils.FormatDate)
-								}
-								if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TbzDiv(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								break
-							}
-						}
-					} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-						if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-							break
-						}
-					} else {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-						preDateDay := preDate.AddDate(0, 0, -1)
-						preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-						for i := 0; i < 35; i++ {
-							if i >= 1 {
-								nextDateDay = nextDateDay.AddDate(0, 0, i)
-								nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-								break
-							} else {
-								if i >= 1 {
-									preDateDay = preDate.AddDate(0, 0, -i)
-									preDateDayStr = nextDateDay.Format(utils.FormatDate)
-								}
-								if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TbzDiv(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								break
-							}
-						}
-					}
-				}
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新同比值数据
-func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_tbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for _, av := range dateArr {
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				val := TbzDiv(currentItem.Value, findItem.Value)
-
-				count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
-				}
-				if count <= 0 {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-				} else {
-					err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-					if err != nil {
-						return err
-					}
-				}
-				utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-				continue
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					for i := 0; i <= 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, i)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							fmt.Println(currentItem.Value, findItem.Value)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-							if err != nil && err.Error() != utils.ErrNoRow() {
-								return err
-							}
-							if count <= 0 {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							} else {
-								err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-								if err != nil {
-									return err
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -i)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-								if err != nil && err.Error() != utils.ErrNoRow() {
-									return err
-								}
-								if count <= 0 {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								} else {
-									err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-									if err != nil {
-										return err
-									}
-								}
-								break
-							}
-						}
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TbzDiv(currentItem.Value, findItem.Value)
-
-						count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-						if err != nil && err.Error() != utils.ErrNoRow() {
-							return err
-						}
-						if count <= 0 {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-						} else {
-							err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-							if err != nil {
-								return err
-							}
-						}
-						break
-					}
-				} else {
-					nextDateDay := preDate.AddDate(0, 0, 1)
-					nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-					preDateDay := preDate.AddDate(0, 0, -1)
-					preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-					for i := 0; i < 35; i++ {
-						if i >= 1 {
-							nextDateDay = nextDateDay.AddDate(0, 0, i)
-							nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-						}
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-							if err != nil && err.Error() != utils.ErrNoRow() {
-								return err
-							}
-							if count <= 0 {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							} else {
-								err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-								if err != nil {
-									return err
-								}
-							}
-							break
-						} else {
-							if i >= 1 {
-								preDateDay = preDate.AddDate(0, 0, -i)
-								preDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								count, err := GetEdbDataCalculateTbzByCodeAndDate(edbCode, av)
-								if err != nil && err.Error() != utils.ErrNoRow() {
-									return err
-								}
-								if count <= 0 {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								} else {
-									err = ModifyEdbDataCalculateTbz(int64(edbInfoId), av, val)
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						}
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateTbzDetail struct {
-	EdbInfoCalculateTbzId int       `orm:"column(edb_info_calculate_tbz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-	StartDate             string    `description:"开始日期"`
-	EndDate               string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateTbzDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-func GetEdbDataCalculateTbzByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate_tbz WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataCalculateTbz(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_calculate_tbz SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新所有同比值数据
-func RefreshAllCalculateTbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	fmt.Println("dataTableName:", dataTableName)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-	fmt.Println("existDataMap:", existDataMap)
-	addSql := ` INSERT INTO edb_data_calculate_tbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existAddDataMap := make(map[string]string)
-	for _, av := range dateArr {
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				val := TbzDiv(currentItem.Value, findItem.Value)
-				if existVal, ok := existDataMap[av]; !ok {
-					if _, existOk := existAddDataMap[av]; !existOk {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-						isAdd = true
-					}
-					existAddDataMap[av] = av
-				} else {
-					if existVal != val {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-				continue
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					for i := 0; i <= 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, i)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								if existVal != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -i)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									if existVal != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-								break
-							}
-						}
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TbzDiv(currentItem.Value, findItem.Value)
-
-						if existVal, ok := existDataMap[av]; !ok {
-							if _, existOk := existAddDataMap[av]; !existOk {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existAddDataMap[av] = av
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-						break
-					}
-				} else {
-					nextDateDay := preDate.AddDate(0, 0, 1)
-					nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-					preDateDay := preDate.AddDate(0, 0, -1)
-					preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-					for i := 0; i < 35; i++ {
-						if i >= 1 {
-							nextDateDay = nextDateDay.AddDate(0, 0, i)
-							nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-						}
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								if existVal != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							if i >= 1 {
-								preDateDay = preDate.AddDate(0, 0, -i)
-								preDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
-
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									if existVal != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-							}
-							break
-						}
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 1010
models/data_manage/edb_info_calculate_tcz.go

@@ -1,1010 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbInfoCalculateTcz struct {
-	EdbInfoCalculateTbzId int       `orm:"column(edb_info_calculate_tcz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-}
-
-//同差值
-func AddCalculateTcz(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("err:", err.Error())
-			o.Rollback()
-		} else {
-			fmt.Println("commit")
-			o.Commit()
-		}
-	}()
-	fmt.Println("req.EdbInfoId:", req.EdbInfoId)
-	if req.EdbInfoId <= 0 {
-		edbInfo := new(EdbInfo)
-		edbInfo.Source = utils.DATA_SOURCE_CALCULATE_TCZ
-		edbInfo.SourceName = "同差值"
-		edbInfo.EdbCode = edbCode
-		edbInfo.EdbName = req.EdbName
-		edbInfo.EdbNameSource = req.EdbName
-		edbInfo.Frequency = req.Frequency
-		edbInfo.Unit = req.Unit
-		edbInfo.ClassifyId = req.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.UniqueCode = uniqueCode
-		edbInfo.CalculateFormula = req.Formula
-		edbInfo.EdbType = 2
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-
-		//calculateItem := new(EdbInfoCalculateTcz)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return edbInfoId, err
-		//}
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = edbInfo.Source
-			calculateMappingItem.SourceName = edbInfo.SourceName
-			go o.Insert(calculateMappingItem)
-		}
-	} else {
-		edbInfoId = req.EdbInfoId
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_TCZ)
-		fmt.Println("dataTableName:", dataTableName)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	if req.EdbInfoId <= 0 {
-		pars = append(pars, req.FromEdbInfoId)
-	} else {
-		pars = append(pars, fromEdbInfo.EdbInfoId)
-	}
-
-	fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return edbInfoId, err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	fmt.Println("Frequency:", fromEdbInfo.Frequency)
-	addSql := ` INSERT INTO edb_data_calculate_tcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existMap := make(map[string]string)
-	for _, av := range dateArr {
-		//fmt.Println("dateArr:", ak, av)
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return edbInfoId, err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				if _, ok := existMap[edbCode+av]; !ok {
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-
-					val := TczSub(currentItem.Value, findItem.Value)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-				}
-				existMap[edbCode+av] = av
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					nextDateDay := preDate
-					preDateDay := preDate
-					for i := 0; i <= 35; i++ {
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //下一年同期->下一个月找到
-							if _, ok := existMap[edbCode+av]; !ok {
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existMap[edbCode+av] = av
-							break
-						} else {
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								if _, ok := existMap[edbCode+av]; !ok {
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TczSub(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existMap[edbCode+av] = av
-								break
-							}
-						}
-						nextDateDay = nextDateDay.AddDate(0, 0, 1)
-						preDateDay = preDateDay.AddDate(0, 0, -1)
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						if _, ok := existMap[edbCode+av]; !ok {
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-						}
-						existMap[edbCode+av] = av
-						break
-					}
-				} else {
-					nextDateDay := preDate
-					preDateDay := preDate
-					for i := 0; i < 35; i++ {
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							if _, ok := existMap[edbCode+av]; !ok {
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existMap[edbCode+av] = av
-							break
-						} else {
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								if _, ok := existMap[edbCode+av]; !ok {
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TczSub(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existMap[edbCode+av] = av
-								break
-							} else {
-
-							}
-						}
-						nextDateDay = nextDateDay.AddDate(0, 0, 1)
-						preDateDay = preDateDay.AddDate(0, 0, -1)
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return edbInfoId, err
-		}
-	}
-	return
-}
-
-func TczSub(a, b float64) string {
-	af := decimal.NewFromFloat(float64(a))
-	fmt.Println(af)
-	bf := decimal.NewFromFloat(float64(b))
-	val, _ := af.Sub(bf).Float64()
-	valStr := utils.SubFloatToString(val, 4)
-	return valStr
-}
-
-//同差值
-func EditCalculateTcz(req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo, edbCode string) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("err:", err.Error())
-			o.Rollback()
-		} else {
-			fmt.Println("commit")
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info
-			SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	existCondition += " AND from_edb_info_id=? "
-	existPars = append(existPars, req.FromEdbInfoId)
-
-	//判断计算指标是否被更换
-	count, err := GetEdbInfoCalculateCountByCondition(req.Source, existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-	if count <= 0 {
-		//删除指标关联计算指标
-		//sql := ` DELETE FROM edb_info_calculate_tcz WHERE edb_info_id = ? `
-		//_, err = o.Raw(sql, edbInfoId).Exec()
-		//if err != nil {
-		//	return
-		//}
-		//
-		//calculateItem := new(EdbInfoCalculateTcz)
-		//calculateItem.CreateTime = time.Now()
-		//calculateItem.ModifyTime = time.Now()
-		//calculateItem.Sort = 1
-		//calculateItem.EdbCode = edbCode
-		//calculateItem.EdbInfoId = edbInfoId
-		//calculateItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		//calculateItem.FromEdbCode = fromEdbInfo.EdbCode
-		//calculateItem.FromEdbName = fromEdbInfo.EdbName
-		//calculateItem.FromSource = fromEdbInfo.Source
-		//calculateItem.FromSourceName = fromEdbInfo.SourceName
-		//
-		//_, err = o.Insert(calculateItem)
-		//if err != nil {
-		//	return
-		//}
-
-		//删除,计算指标关联的,基础指标的关联关系
-		sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-		if err != nil {
-			return
-		}
-
-		//清空原有数据
-		sql = ` DELETE FROM edb_data_calculate_tcz WHERE edb_info_id = ? `
-		_,err=o.Raw(sql, edbInfoId).Exec()
-		if err!=nil {
-			return edbInfoId,err
-		}
-
-		//关联关系
-		{
-			calculateMappingItem := new(EdbInfoCalculateMapping)
-			calculateMappingItem.CreateTime = time.Now()
-			calculateMappingItem.ModifyTime = time.Now()
-			calculateMappingItem.Sort = 1
-			calculateMappingItem.EdbCode = edbCode
-			calculateMappingItem.EdbInfoId = edbInfoId
-			calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-			calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-			calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-			calculateMappingItem.FromSource = fromEdbInfo.Source
-			calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-			calculateMappingItem.FromTag = ""
-			calculateMappingItem.Source = utils.DATA_SOURCE_CALCULATE_TCZ
-			calculateMappingItem.SourceName = "同差值"
-			o.Insert(calculateMappingItem)
-		}
-
-		edbInfoIdStr := strconv.Itoa(edbInfoId)
-
-		//计算数据
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, req.FromEdbInfoId)
-		fmt.Println("EdbInfoId:", req.FromEdbInfoId)
-		dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-		if err != nil {
-			return edbInfoId, err
-		}
-		var dateArr []string
-		dataMap := make(map[string]*EdbInfoSearchData)
-		for _, v := range dataList {
-			dateArr = append(dateArr, v.DataTime)
-			dataMap[v.DataTime] = v
-		}
-
-		addSql := ` INSERT INTO edb_data_calculate_tcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		var isAdd bool
-		for ak, av := range dateArr {
-			fmt.Println(ak, av)
-			currentItem := dataMap[av]
-			if currentItem != nil {
-				//当前日期
-				currentDate, err := time.Parse(utils.FormatDate, av)
-				if err != nil {
-					return edbInfoId, err
-				}
-				//上一年的日期
-				preDate := currentDate.AddDate(-1, 0, 0)
-				preDateStr := preDate.Format(utils.FormatDate)
-				if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-					//dataTime, _ := time.Parse(utils.FormatDate, date)
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-
-					val := TczSub(currentItem.Value, findItem.Value)
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-					utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-					continue
-				} else {
-					if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-						nextDateDay := preDate.AddDate(0, 1, 0)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-						preDateDay := preDate.AddDate(0, -1, 0)
-						preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-						for i := 0; i <= 6; i++ {
-							if i >= 1 {
-								nextDateDay = nextDateDay.AddDate(0, 0, i)
-								nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-								break
-							} else {
-								if i >= 1 {
-									preDateDay = preDate.AddDate(0, 0, -i)
-									preDateDayStr = nextDateDay.Format(utils.FormatDate)
-								}
-								if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TczSub(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								break
-							}
-						}
-					} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-						if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-							break
-						}
-					} else {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-						preDateDay := preDate.AddDate(0, 0, -1)
-						preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-						for i := 0; i < 35; i++ {
-							if i >= 1 {
-								nextDateDay = nextDateDay.AddDate(0, 0, i)
-								nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-								break
-							} else {
-								if i >= 1 {
-									preDateDay = preDate.AddDate(0, 0, -i)
-									preDateDayStr = nextDateDay.Format(utils.FormatDate)
-								}
-								if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-									timestamp := currentDate.UnixNano() / 1e6
-									timestampStr := fmt.Sprintf("%d", timestamp)
-									val := TczSub(currentItem.Value, findItem.Value)
-
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								break
-							}
-						}
-					}
-				}
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			_, err = o.Raw(addSql).Exec()
-			if err != nil {
-				return edbInfoId, err
-			}
-		}
-	}
-	return
-}
-
-//刷新同差值数据
-func RefreshCalculateTcz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_tcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	for ak, av := range dateArr {
-		fmt.Println(ak, av)
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				val := TczSub(currentItem.Value, findItem.Value)
-
-				count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
-				}
-				if count <= 0 {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
-				} else {
-					err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-					if err != nil {
-						return err
-					}
-				}
-				utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-				continue
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					for i := 0; i <= 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-
-							count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-							if err != nil && err.Error() != utils.ErrNoRow() {
-								return err
-							}
-							if count <= 0 {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							} else {
-								err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-								if err != nil {
-									return err
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -1)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-								if err != nil && err.Error() != utils.ErrNoRow() {
-									return err
-								}
-								if count <= 0 {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								} else {
-									err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-									if err != nil {
-										return err
-									}
-								}
-								break
-							}
-						}
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TczSub(currentItem.Value, findItem.Value)
-
-						count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-						if err != nil && err.Error() != utils.ErrNoRow() {
-							return err
-						}
-						if count <= 0 {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-						} else {
-							err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-							if err != nil {
-								return err
-							}
-						}
-						break
-					}
-				} else {
-					for i := 0; i < 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-
-							count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-							if err != nil && err.Error() != utils.ErrNoRow() {
-								return err
-							}
-							if count <= 0 {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							} else {
-								err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-								if err != nil {
-									return err
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -1)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								count, err := GetEdbDataCalculateTczByCodeAndDate(edbCode, av)
-								if err != nil && err.Error() != utils.ErrNoRow() {
-									return err
-								}
-								if count <= 0 {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								} else {
-									err = ModifyEdbDataCalculateTcz(int64(edbInfoId), av, val)
-									if err != nil {
-										return err
-									}
-								}
-								break
-							}
-						}
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}
-
-type EdbInfoCalculateTczDetail struct {
-	EdbInfoCalculateTczId int       `orm:"column(edb_info_calculate_tcz_id);pk"`
-	EdbInfoId             int       `description:"指标id"`
-	EdbCode               string    `description:"指标编码"`
-	FromEdbInfoId         int       `description:"计算指标id"`
-	FromEdbCode           string    `description:"计算指标编码"`
-	FromEdbName           string    `description:"计算指标名称"`
-	FromSource            int       `description:"计算指标来源"`
-	FromSourceName        string    `description:"计算指标来源名称"`
-	FromTag               string    `description:"来源指标标签"`
-	Sort                  int       `description:"计算指标名称排序"`
-	CreateTime            time.Time `description:"创建时间"`
-	ModifyTime            time.Time `description:"修改时间"`
-	StartDate             string    `description:"开始日期"`
-	EndDate               string    `description:"结束日期"`
-}
-
-func GetEdbInfoCalculateTczDetail(edbInfoId int) (item *EdbInfoCalculateTczDetail, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
-			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
-			WHERE a.edb_info_id=? `
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
-	return
-}
-
-func GetEdbDataCalculateTczByCodeAndDate(edbCode string, startDate string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate_tcz WHERE edb_code=? AND data_time=? `
-	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
-	return
-}
-
-func ModifyEdbDataCalculateTcz(edbInfoId int64, dataTime, value string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE edb_data_calculate_tcz SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
-	return
-}
-
-//刷新全部同差值数据
-func RefreshAllCalculateTcz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	if err != nil {
-		return
-	}
-	edbInfoIdStr := strconv.Itoa(edbInfoId)
-	//计算数据
-
-	//计算数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, fromEdbInfo.EdbInfoId)
-
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
-
-	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-	}
-	//获取指标所有数据
-	existDataList := make([]*EdbDataBase, 0)
-	dataTableName := GetEdbDataTableName(source)
-	sql := `SELECT * FROM %s WHERE edb_info_id=? `
-	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
-	if err != nil {
-		return err
-	}
-	existDataMap := make(map[string]string)
-	for _, v := range existDataList {
-		existDataMap[v.DataTime] = v.Value
-	}
-
-	addSql := ` INSERT INTO edb_data_calculate_tcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	var isAdd bool
-	existAddDataMap := make(map[string]string)
-	for _, av := range dateArr {
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.Parse(utils.FormatDate, av)
-			if err != nil {
-				return err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.Parse(utils.FormatDate, date)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				val := TczSub(currentItem.Value, findItem.Value)
-
-				if existVal, ok := existDataMap[av]; !ok {
-					if _, existOk := existAddDataMap[av]; !existOk {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-						isAdd = true
-					}
-					existAddDataMap[av] = av
-				} else {
-					if existVal != val {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-				utils.FileLog.Info("同期找到:" + av + ";" + preDateStr)
-				continue
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					for i := 0; i <= 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								if existVal != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -1)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									if existVal != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-								break
-							}
-						}
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TczSub(currentItem.Value, findItem.Value)
-
-						if existVal, ok := existDataMap[av]; !ok {
-							if _, existOk := existAddDataMap[av]; !existOk {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existAddDataMap[av] = av
-						} else {
-							if existVal != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-						break
-					}
-				} else {
-					for i := 0; i < 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, 1)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TczSub(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								if existVal != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -1)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TczSub(currentItem.Value, findItem.Value)
-
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									if existVal != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = o.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-								break
-							}
-						}
-					}
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		_, err = o.Raw(addSql).Exec()
-		if err != nil {
-			return err
-		}
-	}
-	return
-}

+ 0 - 4
models/data_manage/edb_info_calculate_time_shift.go

@@ -1,4 +0,0 @@
-package data_manage
-
-//时间移位
-

+ 0 - 686
models/data_manage/edb_info_calculate_zjpj.go

@@ -1,686 +0,0 @@
-package data_manage
-
-import (
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"strings"
-	"time"
-)
-
-// AddCalculateZjpj 新增直接拼接数据
-func AddCalculateZjpj(req *EdbInfoCalculateBatchSaveReq, firstEdbInfo, secondEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfoId int, err error) {
-	fmt.Println("AddCalculateZjpj")
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			fmt.Println("AddCalculateZjpj,Err:" + err.Error())
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	var edbInfo *EdbInfo
-	if req.EdbInfoId <= 0 {
-		edbInfo = &EdbInfo{
-			SourceName:       "直接拼接",
-			Source:           utils.DATA_SOURCE_CALCULATE_ZJPJ,
-			EdbCode:          edbCode,
-			EdbName:          req.EdbName,
-			EdbNameSource:    req.EdbName,
-			Frequency:        req.Frequency,
-			Unit:             req.Unit,
-			StartDate:        firstEdbInfo.StartDate,
-			EndDate:          firstEdbInfo.EndDate,
-			ClassifyId:       req.ClassifyId,
-			SysUserId:        sysUserId,
-			SysUserRealName:  sysUserRealName,
-			UniqueCode:       uniqueCode,
-			CreateTime:       time.Now(),
-			ModifyTime:       time.Now(),
-			CalculateFormula: req.Formula,
-			EdbType:          2,
-		}
-		newEdbInfoId, err := o.Insert(edbInfo)
-		if err != nil {
-			return edbInfoId, err
-		}
-		edbInfoId = int(newEdbInfoId)
-	} else {
-		edbInfoId = req.EdbInfoId
-		//查询
-		tmpEdbInfo, tmpErr := GetEdbInfoById(edbInfoId)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		tmpEdbInfo.EdbName = req.EdbName
-		tmpEdbInfo.ClassifyId = req.ClassifyId
-		tmpEdbInfo.Frequency = req.Frequency
-		tmpEdbInfo.Unit = req.Unit
-		tmpEdbInfo.CalculateFormula = req.Formula
-
-		edbInfo = tmpEdbInfo
-
-		//删除指标数据
-		dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_ZJPJ)
-		fmt.Println("dataTableName:" + dataTableName)
-		deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
-		deleteSql = fmt.Sprintf(deleteSql, dataTableName)
-		_, err = o.Raw(deleteSql, req.EdbInfoId).Exec()
-		if err != nil {
-			return 0, err
-		}
-
-		//删除指标关系
-		sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
-		_, err = o.Raw(sql, edbInfoId).Exec()
-	}
-
-	//关联关系
-
-	//第一个指标
-	{
-		calculateMappingItem := new(EdbInfoCalculateMapping)
-		calculateMappingItem.CreateTime = time.Now()
-		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
-		calculateMappingItem.EdbCode = edbCode
-		calculateMappingItem.EdbInfoId = edbInfoId
-		calculateMappingItem.FromEdbInfoId = firstEdbInfo.EdbInfoId
-		calculateMappingItem.FromEdbCode = firstEdbInfo.EdbCode
-		calculateMappingItem.FromEdbName = firstEdbInfo.EdbName
-		calculateMappingItem.FromSource = firstEdbInfo.Source
-		calculateMappingItem.FromSourceName = firstEdbInfo.SourceName
-		calculateMappingItem.FromTag = "A"
-		calculateMappingItem.Source = edbInfo.Source
-		calculateMappingItem.SourceName = edbInfo.SourceName
-		go o.Insert(calculateMappingItem)
-	}
-
-	//第二个指标
-	{
-		calculateMappingItem := new(EdbInfoCalculateMapping)
-		calculateMappingItem.CreateTime = time.Now()
-		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
-		calculateMappingItem.EdbCode = edbCode
-		calculateMappingItem.EdbInfoId = edbInfoId
-		calculateMappingItem.FromEdbInfoId = secondEdbInfo.EdbInfoId
-		calculateMappingItem.FromEdbCode = secondEdbInfo.EdbCode
-		calculateMappingItem.FromEdbName = secondEdbInfo.EdbName
-		calculateMappingItem.FromSource = secondEdbInfo.Source
-		calculateMappingItem.FromSourceName = secondEdbInfo.SourceName
-		calculateMappingItem.FromTag = "B"
-		calculateMappingItem.Source = edbInfo.Source
-		calculateMappingItem.SourceName = edbInfo.SourceName
-		go o.Insert(calculateMappingItem)
-	}
-
-	addDataList := make([]*EdbDataCalculateZjpj, 0)
-
-	//拼接数据
-
-	//第一个指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time < ? AND edb_info_id=? "
-		pars = append(pars, req.Formula, firstEdbInfo.EdbInfoId)
-
-		//第一个指标的数据列表
-		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, firstEdbInfo.Source, 0)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-
-		for _, v := range firstDataList {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataZjpj := &EdbDataCalculateZjpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       edbInfo.EdbCode,
-				DataTime:      v.DataTime,
-				Value:         v.Value,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataZjpj)
-			if len(addDataList) >= 200 {
-				_, tmpErr := o.InsertMulti(len(addDataList), addDataList)
-				if tmpErr != nil {
-					err = tmpErr
-					return
-				}
-				//重新初始化需要加入的数据切片
-				addDataList = make([]*EdbDataCalculateZjpj, 0)
-			}
-		}
-	}
-
-	//第二个指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time >= ? AND edb_info_id = ? "
-		pars = append(pars, req.Formula, secondEdbInfo.EdbInfoId)
-
-		//第二个指标的数据列表
-		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, secondEdbInfo.Source, 0)
-		if tmpErr != nil {
-			return edbInfoId, tmpErr
-		}
-
-		for _, v := range secondDataList {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataZjpj := &EdbDataCalculateZjpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       edbInfo.EdbCode,
-				DataTime:      v.DataTime,
-				Value:         v.Value,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataZjpj)
-			if len(addDataList) >= 200 {
-				_, tmpErr := o.InsertMulti(len(addDataList), addDataList)
-				if tmpErr != nil {
-					err = tmpErr
-					return
-				}
-				//重新初始化需要加入的数据切片
-				addDataList = make([]*EdbDataCalculateZjpj, 0)
-			}
-		}
-	}
-
-	//将剩余的数据入库
-	if len(addDataList) > 0 {
-		_, tmpErr := o.InsertMulti(len(addDataList), addDataList)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-	}
-	return
-}
-
-// EditCalculateZjpj 编辑直接拼接数据
-func EditCalculateZjpj(req *EdbInfoCalculateBatchEditReq, nowEdbInfo, firstEdbInfo, secondEdbInfo *EdbInfo) (edbInfoId int, err error) {
-	edbInfoId = req.EdbInfoId
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//修改指标信息
-	sql := ` UPDATE  edb_info SET
-			  edb_name =?,
-			  edb_name_source=?,
-			  frequency = ?,
-			  unit = ?,
-			  classify_id = ?, 
-			  calculate_formula=?,
-			  modify_time = NOW()
-			WHERE edb_info_id = ? `
-	_, err = o.Raw(sql, req.EdbName, req.EdbName, req.Frequency, req.Unit, req.ClassifyId, req.Formula, edbInfoId).Exec()
-	if err != nil {
-		return
-	}
-
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfoId)
-
-	//查询出所有的关联指标
-	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-
-	var existItemA, existItemB *EdbInfoCalculateMapping
-	for _, existItem := range existList {
-		if existItem.FromTag == "A" {
-			existItemA = existItem
-		} else if existItem.FromTag == "B" {
-			existItemB = existItem
-		}
-	}
-
-	addDataList := make([]*EdbDataCalculateZjpj, 0)
-	firstDataList := make([]*EdbInfoSearchData, 0)
-	secondDataList := make([]*EdbInfoSearchData, 0)
-
-	//如果 之前的拼接日期 与 现在的拼接日期 不一致的话,需要做以下处理
-	nowFormulaDate, _ := time.ParseInLocation(utils.FormatDate, nowEdbInfo.CalculateFormula, time.Local)
-	reqFormulaDate, _ := time.ParseInLocation(utils.FormatDate, req.Formula, time.Local)
-
-	//如果前后选择的日期不一致,那么需要删除一部分数据
-	if nowEdbInfo.CalculateFormula != req.Formula {
-		var startDate, endDate time.Time
-		//如果当前选择的日期 小于 之前选择的日期
-		if reqFormulaDate.Before(nowFormulaDate) {
-			startDate = reqFormulaDate
-			endDate = nowFormulaDate
-		} else { //如果当前选择的日期 大于 之前选择的日期
-			startDate = nowFormulaDate
-			endDate = reqFormulaDate
-		}
-		//删除 之前日期 与 当前日期 之间的指标数据
-		sql = ` DELETE FROM edb_data_calculate_zjpj WHERE edb_info_id = ? and data_time >= ? and data_time < ?`
-		_, err = o.Raw(sql, edbInfoId, startDate, endDate).Exec()
-		if err != nil {
-			err = errors.New("删除 之前日期 与 当前日期 之间的指标数据失败,Err:" + err.Error())
-			return
-		}
-	}
-	//第一个指标数据
-	{
-		var condition string
-		var pars []interface{}
-		if existItemA.FromEdbInfoId != firstEdbInfo.EdbInfoId {
-			//删除之前的A指标关联关系
-			sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
-			_, err = o.Raw(sql, edbInfoId, existItemA.FromEdbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除拼接日期之前的指标关联关系失败,Err:" + err.Error())
-				return
-			}
-
-			//删除之前所有的A指标数据
-			sql = ` DELETE FROM edb_data_calculate_zjpj WHERE edb_info_id = ? and data_time < ?`
-			_, err = o.Raw(sql, edbInfoId, req.Formula).Exec()
-			if err != nil {
-				err = errors.New("删除拼接日期之前的数据失败,Err:" + err.Error())
-				return
-			}
-
-			//获取第一个指标的数据列表
-			condition += " AND data_time < ? AND edb_info_id=? "
-			pars = append(pars, req.Formula, firstEdbInfo.EdbInfoId)
-
-			tmpFirstDataList, tmpErr := GetEdbDataListAll(condition, pars, firstEdbInfo.Source, 0)
-			if tmpErr != nil {
-				return edbInfoId, tmpErr
-			}
-			firstDataList = tmpFirstDataList
-
-			//添加新的指标关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = nowEdbInfo.EdbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = firstEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = firstEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = firstEdbInfo.EdbName
-				calculateMappingItem.FromSource = firstEdbInfo.Source
-				calculateMappingItem.FromSourceName = firstEdbInfo.SourceName
-				calculateMappingItem.FromTag = "A"
-				calculateMappingItem.Source = nowEdbInfo.Source
-				calculateMappingItem.SourceName = nowEdbInfo.SourceName
-				go o.Insert(calculateMappingItem)
-			}
-		} else {
-			if req.Formula != nowEdbInfo.CalculateFormula {
-				//获取第一个指标的数据列表
-				condition += " AND data_time >= ?  AND data_time < ? AND edb_info_id=? "
-				pars = append(pars, nowFormulaDate, reqFormulaDate, firstEdbInfo.EdbInfoId)
-
-				tmpFirstDataList, tmpErr := GetEdbDataListAll(condition, pars, firstEdbInfo.Source, 0)
-				if tmpErr != nil {
-					return edbInfoId, tmpErr
-				}
-				firstDataList = tmpFirstDataList
-			}
-		}
-
-		//待插入数据
-		for _, v := range firstDataList {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataZjpj := &EdbDataCalculateZjpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       nowEdbInfo.EdbCode,
-				DataTime:      v.DataTime,
-				Value:         v.Value,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataZjpj)
-		}
-	}
-
-	//第二个指标数据
-	{
-		var condition string
-		var pars []interface{}
-
-		if existItemB.FromEdbInfoId != secondEdbInfo.EdbInfoId {
-			//删除之前的B指标关联关系
-			sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
-			_, err = o.Raw(sql, edbInfoId, existItemB.FromEdbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除拼接日期之后的指标关联关系失败,Err:" + err.Error())
-				return
-			}
-
-			//删除历史拼接日期之前所有的B指标数据
-			sql = ` DELETE FROM edb_data_calculate_zjpj WHERE edb_info_id = ? and data_time >= ?`
-			_, err = o.Raw(sql, edbInfoId, nowEdbInfo.CalculateFormula).Exec()
-			if err != nil {
-				err = errors.New("删除历史拼接日期之后的数据失败,Err:" + err.Error())
-				return
-			}
-
-			//第二个指标的数据列表
-			condition = " AND data_time >= ?  AND edb_info_id=? "
-			pars = append(pars, reqFormulaDate, secondEdbInfo.EdbInfoId)
-			tmpSecondDataList, tmpErr := GetEdbDataListAll(condition, pars, secondEdbInfo.Source, 0)
-			if tmpErr != nil {
-				return edbInfoId, tmpErr
-			}
-			secondDataList = tmpSecondDataList
-
-			//添加新的指标关系
-			{
-				calculateMappingItem := new(EdbInfoCalculateMapping)
-				calculateMappingItem.CreateTime = time.Now()
-				calculateMappingItem.ModifyTime = time.Now()
-				calculateMappingItem.Sort = 1
-				calculateMappingItem.EdbCode = nowEdbInfo.EdbCode
-				calculateMappingItem.EdbInfoId = edbInfoId
-				calculateMappingItem.FromEdbInfoId = secondEdbInfo.EdbInfoId
-				calculateMappingItem.FromEdbCode = secondEdbInfo.EdbCode
-				calculateMappingItem.FromEdbName = secondEdbInfo.EdbName
-				calculateMappingItem.FromSource = secondEdbInfo.Source
-				calculateMappingItem.FromSourceName = secondEdbInfo.SourceName
-				calculateMappingItem.FromTag = "B"
-				calculateMappingItem.Source = nowEdbInfo.Source
-				calculateMappingItem.SourceName = nowEdbInfo.SourceName
-				go o.Insert(calculateMappingItem)
-			}
-		} else {
-			if req.Formula != nowEdbInfo.CalculateFormula {
-				//获取第二个指标的数据列表
-				condition += " AND data_time >= ?  AND data_time < ? AND edb_info_id=? "
-				pars = append(pars, reqFormulaDate, nowFormulaDate, secondEdbInfo.EdbInfoId)
-
-				tmpSecondDataList, tmpErr := GetEdbDataListAll(condition, pars, secondEdbInfo.Source, 0)
-				if tmpErr != nil {
-					return edbInfoId, tmpErr
-				}
-				secondDataList = tmpSecondDataList
-			}
-		}
-
-		//待插入数据
-		for _, v := range secondDataList {
-			//时间戳
-			currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-			timestamp := currentDate.UnixNano() / 1e6
-
-			edbDataZjpj := &EdbDataCalculateZjpj{
-				EdbInfoId:     edbInfoId,
-				EdbCode:       nowEdbInfo.EdbCode,
-				DataTime:      v.DataTime,
-				Value:         v.Value,
-				Status:        1,
-				CreateTime:    time.Now(),
-				ModifyTime:    time.Now(),
-				DataTimestamp: timestamp,
-			}
-			addDataList = append(addDataList, edbDataZjpj)
-		}
-	}
-
-	//数据入库
-	tmpAddDataList := make([]*EdbDataCalculateZjpj, 0)
-	for _, v := range addDataList {
-		tmpAddDataList = append(tmpAddDataList, v)
-
-		if len(tmpAddDataList) >= 200 {
-			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-			//重新初始化需要加入的数据切片
-			tmpAddDataList = make([]*EdbDataCalculateZjpj, 0)
-		}
-	}
-	//最后如果还有需要新增的数据,那么就统一入库
-	if len(tmpAddDataList) > 0 {
-		_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-	}
-
-	return
-}
-
-// RefreshAllCalculateZjpj 刷新所有 直接拼接 数据
-func RefreshAllCalculateZjpj(edbInfo *EdbInfo) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	//查询当前指标现有的数据
-	var condition string
-	var pars []interface{}
-	condition += " AND edb_info_id=? "
-	pars = append(pars, edbInfo.EdbInfoId)
-
-	dataList, err := GetAllEdbDataCalculateZjpjByEdbInfoId(edbInfo.EdbInfoId)
-	if err != nil {
-		return err
-	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbDataCalculateZjpj)
-	removeDataTimeMap := make(map[string]int) //需要移除的日期数据
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
-		removeDataTimeMap[v.DataTime] = 1
-	}
-
-	//查询关联指标信息
-	var existCondition string
-	var existPars []interface{}
-	existCondition += " AND edb_info_id=? "
-	existPars = append(existPars, edbInfo.EdbInfoId)
-	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
-	if err != nil {
-		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
-		return
-	}
-
-	var existItemA, existItemB *EdbInfoCalculateMapping
-	for _, existItem := range existList {
-		if existItem.FromTag == "A" {
-			existItemA = existItem
-		} else if existItem.FromTag == "B" {
-			existItemB = existItem
-		}
-	}
-
-	addDataList := make([]*EdbDataCalculateZjpj, 0)
-	//第一个指标
-	{
-		var condition string
-		var pars []interface{}
-
-		condition += " AND data_time < ? AND edb_info_id=? "
-		pars = append(pars, edbInfo.CalculateFormula, existItemA.FromEdbInfoId)
-
-		//第一个指标的数据列表
-		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemA.FromSource, 0)
-		if tmpErr != nil {
-			return tmpErr
-		}
-
-		for _, v := range firstDataList {
-			//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该元素
-			if _, ok := removeDataTimeMap[v.DataTime]; ok {
-				delete(removeDataTimeMap, v.DataTime)
-			}
-			//时间戳
-			if edbData, ok := dataMap[v.DataTime]; ok {
-				if edbData.Value != v.Value {
-					//更新指标数据
-					edbData.Value = v.Value
-					o.Update(edbData, "Value")
-				}
-			} else {
-				//时间戳
-				currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-				timestamp := currentDate.UnixNano() / 1e6
-
-				edbDataZjpj := &EdbDataCalculateZjpj{
-					EdbInfoId:     edbInfo.EdbInfoId,
-					EdbCode:       edbInfo.EdbCode,
-					DataTime:      v.DataTime,
-					Value:         v.Value,
-					Status:        1,
-					CreateTime:    time.Now(),
-					ModifyTime:    time.Now(),
-					DataTimestamp: timestamp,
-				}
-				addDataList = append(addDataList, edbDataZjpj)
-			}
-		}
-	}
-
-	//第二个指标
-	{
-		condition = ``
-		pars = make([]interface{}, 0)
-
-		condition += " AND data_time >= ? AND edb_info_id = ? "
-		pars = append(pars, edbInfo.CalculateFormula, existItemB.FromEdbInfoId)
-
-		//第二个指标的数据列表
-		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemB.FromSource, 0)
-		if tmpErr != nil {
-			return tmpErr
-		}
-
-		for _, v := range secondDataList {
-			//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该元素
-			if _, ok := removeDataTimeMap[v.DataTime]; ok {
-				delete(removeDataTimeMap, v.DataTime)
-			}
-
-			if edbData, ok := dataMap[v.DataTime]; ok {
-				if edbData.Value != v.Value {
-					//更新指标数据
-					edbData.Value = v.Value
-					edbData.ModifyTime = time.Now()
-					_, tmpErr := o.Update(edbData, "Value", "ModifyTime")
-					if tmpErr != nil {
-						fmt.Println("tmpErr:", tmpErr)
-					}
-				}
-			} else {
-				//时间戳
-				currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
-				timestamp := currentDate.UnixNano() / 1e6
-
-				edbDataZjpj := &EdbDataCalculateZjpj{
-					EdbInfoId:     edbInfo.EdbInfoId,
-					EdbCode:       edbInfo.EdbCode,
-					DataTime:      v.DataTime,
-					Value:         v.Value,
-					Status:        1,
-					CreateTime:    time.Now(),
-					ModifyTime:    time.Now(),
-					DataTimestamp: timestamp,
-				}
-				addDataList = append(addDataList, edbDataZjpj)
-			}
-		}
-	}
-
-	//删除已经不存在的累计同比拼接指标数据(由于同比值当日的数据删除了)
-	{
-		removeDateList := make([]string, 0)
-		for dateTime := range removeDataTimeMap {
-			removeDateList = append(removeDateList, dateTime)
-		}
-		if len(removeDateList) > 0 {
-			removeDateStr := strings.Join(removeDateList, `","`)
-			removeDateStr = `"` + removeDateStr + `"`
-			//如果拼接指标变更了,那么需要删除所有的指标数据
-			tableName := GetEdbDataTableName(edbInfo.Source)
-			sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
-
-			_, err = o.Raw(sql, edbInfo.EdbInfoId).Exec()
-			if err != nil {
-				err = errors.New("删除不存在的直接拼接指标数据失败,Err:" + err.Error())
-				return
-			}
-		}
-	}
-
-	//数据入库
-	tmpAddDataList := make([]*EdbDataCalculateZjpj, 0)
-	for _, v := range addDataList {
-		tmpAddDataList = append(tmpAddDataList, v)
-
-		if len(tmpAddDataList) >= 200 {
-			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-			//重新初始化需要加入的数据切片
-			tmpAddDataList = make([]*EdbDataCalculateZjpj, 0)
-		}
-	}
-	//最后如果还有需要新增的数据,那么就统一入库
-	if len(tmpAddDataList) > 0 {
-		_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-	}
-	return
-}

+ 0 - 29
models/data_manage/edb_info_log.go

@@ -1,29 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type EdbInfoLog struct {
-	EdbInfoLogId    int `orm:"column(edb_info_log_id);pk"`
-	EdbInfoId       int
-	SourceName      string `description:"来源名称"`
-	Source          int    `description:"来源id"`
-	EdbCode         string `description:"指标编码"`
-	EdbName         string `description:"指标名称"`
-	ClassifyId      int    `description:"分类id"`
-	SysUserId       int
-	SysUserRealName string
-	CreateTime      time.Time
-	Content         string `description:"内容"`
-	Status          string `description:"状态"`
-	Method          string `description:"执行方法"`
-}
-
-func AddEdbInfoLog(item *EdbInfoLog) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}

+ 0 - 86
models/data_manage/edb_info_updates.go

@@ -1,86 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-)
-
-type UpdatesStatisticalItem struct {
-	Total  int
-	Source int
-}
-
-func GetUpdatesStatistical(condition string, pars []interface{}) (list []*UpdatesStatisticalItem, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS total,source FROM edb_info
-			WHERE 1=1 `
-	sql += condition
-	sql += ` GROUP BY source  `
-	_, err = o.Raw(sql, pars).QueryRows(&list)
-	return
-}
-
-type UpdatesStatisticalResp struct {
-	ThsUpdate          int `description:"同花顺已更新"`
-	ThsNotUpdate       int `description:"同花顺未更新"`
-	WindUpdate         int `description:"wind已更新"`
-	WindNotUpdate      int `description:"wind未更新"`
-	PbUpdate           int `description:"彭博已更新"`
-	PbNotUpdate        int `description:"彭博未更新"`
-	LzUpdate           int `description:"隆众已更新"`
-	LzNotUpdate        int `description:"隆众未更新"`
-	SmmUpdate          int `description:"Smm已更新"`
-	SmmNotUpdate       int `description:"Smm未更新"`
-	MysteelUpdate      int `description:"钢联已更新"`
-	MysteelNotUpdate   int `description:"钢联未更新"`
-	CalculateUpdate    int `description:"计算指标已更新"`
-	CalculateNotUpdate int `description:"计算指标未更新"`
-	ManualUpdate       int `description:"手工指标已更新"`
-	ManualNotUpdate    int `description:"手工指标未更新"`
-}
-
-/*
-DATA_SOURCE_THS                 = iota + 1 //同花顺
-	DATA_SOURCE_WIND                           //wind
-	DATA_SOURCE_PB                             //彭博
-	DATA_SOURCE_CALCULATE                      //指标运算
-	DATA_SOURCE_CALCULATE_LJZZY                //累计值转月
-	DATA_SOURCE_CALCULATE_TBZ                  //同比值
-	DATA_SOURCE_CALCULATE_TCZ                  //同差值
-	DATA_SOURCE_CALCULATE_NSZYDPJJS            //N数值移动平均计算
-	DATA_SOURCE_MANUAL                         //手工指标
-	DATA_SOURCE_LZ                             //隆众
-	DATA_SOURCE_YS                             //有色
-	DATA_SOURCE_CALCULATE_HBZ                  //环比值->12
-	DATA_SOURCE_CALCULATE_HCZ                  //环差值->13
-	DATA_SOURCE_CALCULATE_BP                   //变频->14
-	DATA_SOURCE_GL                             //钢联->15
-*/
-
-func GetUpdatesList(condition string, pars []interface{}, startSize, pageSize int) (list []*EdbInfoView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM edb_info
-			WHERE 1=1 `
-	sql += condition
-	sql += ` LIMIT ?,? `
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
-	return
-}
-
-func GetUpdatesListTotal(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM edb_info
-			WHERE 1=1 `
-	sql += condition
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-type UpdatesListResp struct {
-	List   []*EdbInfoView
-	Total  int
-	Paging *paging.PagingItem
-}

+ 0 - 112
models/data_manage/gl_data.go

@@ -1,112 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-)
-
-type GlClassify struct {
-	BreedShortName string `orm:"column(BREED_SHORT_NAME)" description:"分类名称"`
-}
-
-func GetGlSurveyClassify() (items []*GlClassify, err error) {
-	sql := ` SELECT CASE WHEN BREED_SHORT_NAME IS NULL THEN '无' ELSE BREED_SHORT_NAME END BREED_SHORT_NAME  FROM mb_index_main_info GROUP BY BREED_SHORT_NAME ORDER BY BREED_SHORT_NAME ASC `
-	o := orm.NewOrm()
-	o.Using("gl")
-	o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type GlFrequency struct {
-	Frequency string `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
-}
-
-func GetGlFrequencyByClassifyId(breedShortName string) (items []*GlFrequency, err error) {
-	o := orm.NewOrm()
-	o.Using("gl")
-	if breedShortName == "无" {
-		sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
-		_, err = o.Raw(sql).QueryRows(&items)
-		return
-	} else {
-		sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
-		_, err = o.Raw(sql, breedShortName).QueryRows(&items)
-		return
-	}
-}
-
-type GlIndex struct {
-	Id            int    `orm:"column(ID)"`
-	IndexCode     string `orm:"column(INDEX_CODE)"`
-	IndexName     string `orm:"column(INDEX_NAME)"`
-	UnitName      string `orm:"column(UNIT_NAME)"`
-	FrequencyName string `orm:"column(FREQUENCY_NAME)"`
-	UpdateTime    string `orm:"column(UPDATE_TIME)"`
-}
-
-func GetGlIndex(breedShortName, frequency string) (items []*GlIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("gl")
-	if breedShortName == "无" {
-		sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
-		_, err = o.Raw(sql, frequency).QueryRows(&items)
-		return
-	} else {
-		sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME=? AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
-		_, err = o.Raw(sql, breedShortName, frequency).QueryRows(&items)
-		return
-	}
-}
-
-type GlIndexList struct {
-	Id            int                `orm:"column(ID)"`
-	IndexCode     string             `orm:"column(INDEX_CODE)"`
-	IndexName     string             `orm:"column(INDEX_NAME)"`
-	UnitName      string             `orm:"column(UNIT_NAME)"`
-	FrequencyName string             `orm:"column(FREQUENCY_NAME)"`
-	UpdateTime    string             `orm:"column(UPDATE_TIME)"`
-	Paging        *paging.PagingItem `description:"分页数据"`
-	DataList      []*GlIndexData
-}
-
-type GlIndexData struct {
-	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
-	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
-}
-
-func GetGlIndexData(indexCode string, startSize, pageSize int) (items []*GlIndexData, err error) {
-	//sql := ` SELECT *  FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
-	sql := ` SELECT * FROM (
-	SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=?
-	ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC 
-	)AS t
-	GROUP BY t.DATA_DATE
-	ORDER BY t.DATA_DATE DESC LIMIT ?,? `
-	o := orm.NewOrm()
-	o.Using("gl")
-	_, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
-	return
-}
-
-func GetGlIndexByCode(indexCode string) (items *GlIndex, err error) {
-	sql := ` SELECT *  FROM mb_index_main_info WHERE INDEX_CODE=? `
-	o := orm.NewOrm()
-	o.Using("gl")
-	err = o.Raw(sql, indexCode).QueryRow(&items)
-	return
-}
-
-func GetGlIndexDataCount(indexCode string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("gl")
-	sql := `SELECT COUNT(1) AS count FROM (
-			SELECT * FROM (
-				SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=?
-				ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC 
-				)AS t
-				GROUP BY t.DATA_DATE
-				ORDER BY t.DATA_DATE DESC
-			)AS n `
-	err = o.Raw(sql, indexCode).QueryRow(&count)
-	return
-}

+ 0 - 8
models/data_manage/holiday.go

@@ -1,8 +0,0 @@
-package data_manage
-
-import "time"
-
-type Holiday struct {
-	Year        int
-	HolidayDate time.Time
-}

+ 0 - 108
models/data_manage/lz_data.go

@@ -1,108 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type LzClassify struct {
-	BreedId   int    `description:"分类id"`
-	BreedName string `description:"分类名称"`
-}
-
-func GetLzSurveyClassify() (items []*LzClassify, err error) {
-	sql := ` SELECT breed_id,breed_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type LzFrequency struct {
-	Frequency int `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
-}
-
-func GetLzFrequencyByClassifyId(breedId int) (items []*LzFrequency, err error) {
-	sql := ` SELECT frequency  FROM longzhong_survey_product WHERE breed_id=? GROUP BY frequency ORDER BY frequency ASC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, breedId).QueryRows(&items)
-	return
-}
-
-type LongzhongSurveyProduct struct {
-	SurveyProductId      int `orm:"column(survey_product_id);pk"`
-	ProjectQuotaId       int64
-	BreedId              string
-	BreedName            string
-	QuotaId              string
-	QuotaName            string
-	UnitId               string
-	UnitName             string
-	SampleType           int64
-	SampleId             string
-	SampleName           string
-	DeviceId             string
-	Device               string
-	ProductCraftId       string
-	ProductCraft         string
-	ProductLine          string
-	InputMode            int64
-	Frequency            int64
-	InputValue           string
-	TaskShouldFinishTime int
-	CustomId             string
-	CustomType           int64
-	Custom               string
-	QuotaSampleId        int64
-	StartDate            string
-	EndDate              string
-	ModifyTime           time.Time
-	LzCode               string
-}
-
-func GetLongzhongSurveyProduct(breedId, frequency int) (items []*LongzhongSurveyProduct, err error) {
-	sql := ` SELECT *  FROM longzhong_survey_product WHERE breed_id=? AND frequency=? ORDER BY survey_product_id ASC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, breedId, frequency).QueryRows(&items)
-	return
-}
-
-type LzProductList struct {
-	SurveyProductId int    `orm:"column(survey_product_id);pk"`
-	BreedName       string `description:"品种名称"`
-	QuotaName       string `description:"指标名称"`
-	UnitName        string `description:"单位"`
-	SampleType      int64  `description:"样本类型 0-空 1-企业 2-港口 3-运距 4-区域/国家 99-不确定"`
-	SampleName      string `description:"样本名称"`
-	Device          string `description:"设备"`
-	Frequency       int64  `description:"频度"`
-	Custom          string `description:"扩展字段"`
-	StartDate       string `description:"开始日期"`
-	EndDate         string `description:"结束日期"`
-	ModifyTime      string `description:"修改时间"`
-	LzCode          string `description:"指标编码"`
-	DataList        []*LzProductData
-}
-
-type LzProductData struct {
-	InputValue string `description:"日期"`
-	DataTime   string `description:"值"`
-}
-
-func GetLongzhongSurveyProductData(surveyProductId int) (items []*LzProductData, err error) {
-	sql := ` SELECT *  FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, surveyProductId).QueryRows(&items)
-	return
-}
-
-func GetLongzhongSurveyProductByCode(lzCode string) (items *LongzhongSurveyProduct, err error) {
-	sql := ` SELECT *  FROM longzhong_survey_product WHERE lz_code=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, lzCode).QueryRow(&items)
-	return
-}

+ 0 - 25
models/data_manage/manual.go

@@ -1,25 +0,0 @@
-package data_manage
-
-import "github.com/rdlucklib/rdluck_tools/orm"
-
-type ManualSysUser struct {
-	ItemId   int    `description:"部门/组/用户 id"`
-	ItemName string `description:"部门/组/用户 名称"`
-	Children []*ManualSysUser
-}
-
-type ManualClassifyEdbInfoCount struct {
-	ClassifyId int
-	Total      int
-}
-
-func GetManualClassifyEdbInfoCount() (items []*ManualClassifyEdbInfoCount, err error) {
-	sql := ` SELECT a.classify_id,COUNT(1) AS total FROM edbdata_classify AS a
-			INNER JOIN edbinfo AS b ON a.classify_id=b.classify_id
-			WHERE a.is_show=1
-			GROUP BY a.classify_id `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}

+ 0 - 156
models/data_manage/manual_classify.go

@@ -1,156 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type EdbdataClassify struct {
-	ClassifyId   int       `orm:"column(classify_id);pk" description:"分类id"`
-	ClassifyName string    `description:"分类名称"`
-	ParentId     int       `description:"父级id"`
-	CreateTime   time.Time `description:"创建时间"`
-	Sort         int       `description:"排序"`
-	IsShow       int       `description:"是否显示"`
-}
-
-type EdbdataClassifyList struct {
-	ClassifyId   int       `description:"分类id"`
-	ClassifyName string    `description:"分类名称"`
-	ParentId     int       `description:"父级id"`
-	CreateTime   time.Time `description:"创建时间"`
-	Sort         int       `description:"排序"`
-	IsShow       int       `description:"是否显示"`
-	Total        int       `description:"指标总数"`
-}
-
-func AddEdbdataClassify(item *EdbdataClassify) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type ManualClassifyList struct {
-	ClassifyId   int
-	ClassifyName string
-	ParentId     int
-	CheckList    []int
-	Child        []*ManualClassifyList
-}
-
-func GetManualClassifyAll(adminId int) (items []*ManualClassifyList, err error) {
-	var newItems []*ManualClassifyList
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 AND is_show=1 ORDER BY sort ASC `
-	_, err = o.Raw(sql).QueryRows(&newItems)
-	if err != nil {
-		return
-	}
-	classifyLen := len(newItems)
-	for i := 0; i < classifyLen; i++ {
-		var childItems []*ManualClassifyList
-		parentId := newItems[i].ClassifyId
-		childSql := ``
-		childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=? AND is_show=1 ORDER BY sort ASC "
-		_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
-		if err != nil {
-			return
-		}
-		checkList := make([]int, 0)
-		for _, v := range childItems {
-			if v.ParentId > 0 {
-				count, err := GetManualUserClassifyCount(adminId, v.ClassifyId)
-				if err != nil {
-					return items, err
-				}
-				if count > 0 {
-					checkList = append(checkList, v.ClassifyId)
-				}
-			}
-		}
-		newItems[i].CheckList = checkList
-
-		newItems[i].Child = childItems
-	}
-
-	for _, v := range newItems {
-		if v.ParentId > 0 {
-			count, err := GetManualUserClassifyCount(adminId, v.ClassifyId)
-			if err != nil {
-				return items, err
-			}
-			if count > 0 {
-				v.CheckList = append(v.CheckList, v.ClassifyId)
-			}
-		}
-		childLen := len(v.Child)
-		if childLen > 0 {
-			items = append(items, v)
-		}
-	}
-	return
-}
-
-type AddManualClassifyReq struct {
-	ClassifyName string `description:"分类名称"`
-	ParentId     int    `description:"父级id,第一级传0"`
-}
-
-func GetManualClassifyCount(classifyName string, parentId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT COUNT(1) AS count FROM edbdata_classify WHERE parent_id=? AND classify_name=? `
-	err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
-	return
-}
-
-func GetManualClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
-	err = o.Raw(sql, classifyName).QueryRow(&item)
-	return
-}
-
-func ModifyManualClassifyIsShow(isShow, classifyId, parentId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `UPDATE edbdata_classify SET is_show=?,parent_id=? WHERE classify_id=? `
-	_, err = o.Raw(sql, isShow, parentId, classifyId).Exec()
-	return
-}
-
-type EditManualClassifyReq struct {
-	ClassifyName string `description:"分类名称"`
-	ClassifyId   int    `orm:"column(classify_id);pk" description:"分类id"`
-}
-
-func GetManualClassifyById(classifyId int) (item *EdbdataClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` SELECT * FROM edbdata_classify WHERE classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-func ModifyManualClassifyName(classifyName string, classifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `UPDATE edbdata_classify SET classify_name=? WHERE classify_id=? `
-	_, err = o.Raw(sql, classifyName, classifyId).Exec()
-	return
-}
-
-func GetManualClassifyAllByCondition(condition string) (items []*EdbdataClassifyList, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 `
-	if condition != "" {
-		sql += condition
-	}
-	sql += `  ORDER BY sort ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}

+ 0 - 112
models/data_manage/manual_user.go

@@ -1,112 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type ManualUser struct {
-	ManualUserId    int       `orm:"column(manual_user_id);pk"`
-	AdminId         int       `description:"用户id"`
-	AdminRealName   string    `description:"用户姓名"`
-	SysUserId       int       `description:"创建人id"`
-	SysUserRealName string    `description:"创建人姓名"`
-	CreateTime      time.Time `description:"创建时间"`
-}
-
-func DeleteManualUser(adminId int) (err error) {
-	sql := `DELETE FROM manual_user WHERE admin_id=? `
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Raw(sql, adminId).Exec()
-	return
-}
-
-func AddManualUser(item *ManualUser) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Insert(item)
-	return
-}
-
-type ManualUserItem struct {
-	AdminId       int    `description:"用户id"`
-	AdminRealName string `description:"用户姓名"`
-}
-
-func GetManualUserList() (list []*ManualUserItem, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT admin_id,admin_real_name FROM manual_user
-			GROUP BY admin_id
-			ORDER BY create_time DESC `
-	fmt.Println("GetManualUserList:",sql)
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
-type ManualUserList struct {
-	AdminId       int `description:"用户id"`
-	AdminRealName int `description:"用户姓名"`
-}
-
-func GetManualSysuserAll() (list []*ManualUserList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM manual_user
-			ORDER BY create_time ASC `
-	o.Raw(sql).QueryRows()
-	return
-}
-
-type ManualSysUserClassifySaveReq struct {
-	AdminId    int   `description:"用户id"`
-	ClassifyId []int `description:"分类id数组"`
-}
-
-type ManualUserClassify struct {
-	ManualUserClassifyId int `orm:"column(manual_user_classify_id);pk"`
-	AdminId              int
-	ClassifyId           int
-	CreateTime           time.Time
-}
-
-func AddManualUserClassifyMulti(items []*ManualUserClassify) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.InsertMulti(1, items)
-	return
-}
-
-func DeleteManualUserClassifyCount(adminId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` DELETE FROM manual_user_classify WHERE admin_id=? `
-	_, err = o.Raw(sql, adminId).Exec()
-	return
-}
-
-func GetManualUserClassifyCount(adminId, classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM manual_user_classify WHERE admin_id=? AND classify_id=? `
-	err = o.Raw(sql, adminId, classifyId).QueryRow(&count)
-	return
-}
-
-func GetManualUserCount(adminId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM manual_user WHERE admin_id=? `
-	err = o.Raw(sql, adminId).QueryRow(&count)
-	return
-}
-
-func GetManualUserSetClassify(adminId int) (list []*EdbdataClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM manual_user_classify WHERE admin_id=? `
-	_, err = o.Raw(sql, adminId).QueryRows(&list)
-	return
-}

+ 0 - 576
models/data_manage/my_chart.go

@@ -1,576 +0,0 @@
-package data_manage
-
-import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"time"
-)
-
-type ChartListResp struct {
-	Paging *paging.PagingItem
-	List   []*ChartInfoView
-}
-
-func GetChartListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartInfoView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM chart_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	//sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
-	sql += " ORDER BY create_time DESC LIMIT ?,? "
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
-	return
-}
-
-func GetChartListCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-type MyChartClassify struct {
-	MyChartClassifyId   int `orm:"column(my_chart_classify_id);pk"`
-	MyChartClassifyName string
-	Sort                int       `json:"-" description:"排序字段,值越小,排的越靠前"`
-	AdminId             int       `json:"-"`
-	CreateTime          time.Time `json:"-"`
-	ModifyTime          time.Time `json:"-"`
-}
-
-func AddMyChartClassify(item *MyChartClassify) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Insert(item)
-	return
-}
-
-func GetMyChartClassifyAll(adminId int) (item []*MyChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart_classify WHERE 1=1 AND admin_id=? `
-	sql += " ORDER BY sort asc, my_chart_classify_id desc "
-	_, err = o.Raw(sql, adminId).QueryRows(&item)
-	return
-}
-
-type MyChartClassifyResp struct {
-	List []*MyChartClassify
-}
-
-type MyChartClassifyAddReq struct {
-	MyChartClassifyName string `description:"分类名称"`
-}
-
-func GetMyChartClassifyCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM my_chart_classify WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-func GetMyChartClassifyById(adminId, myChartClassifyId int) (item *MyChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart_classify WHERE admin_id=? AND my_chart_classify_id=? `
-	err = o.Raw(sql, adminId, myChartClassifyId).QueryRow(&item)
-	return
-}
-
-type MyChartClassifyEditReq struct {
-	MyChartClassifyId   int    `description:"分类ID"`
-	MyChartClassifyName string `description:"分类名称"`
-}
-
-// MyChartClassifyMoveReq 移动分类请求参数
-type MyChartClassifyMoveReq struct {
-	MyChartClassifyId int `description:"分类id"`
-	PrevClassifyId    int `description:"上一个兄弟节点分类id"`
-	NextClassifyId    int `description:"下一个兄弟节点分类id"`
-}
-
-func ModifyMyChartClassify(myChartClassifyId int, myChartClassifyName string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `UPDATE my_chart_classify SET my_chart_classify_name=?,modify_time=NOW() WHERE my_chart_classify_id=?`
-	_, err = o.Raw(sql, myChartClassifyName, myChartClassifyId).Exec()
-	return
-}
-
-type MyChartClassifyDeleteReq struct {
-	MyChartClassifyId int `description:"分类ID"`
-}
-
-func DeleteMyChartClassify(myChartClassifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	//o.Begin()
-	//
-	//defer func() {
-	//	if err != nil {
-	//		o.Rollback()
-	//	} else {
-	//		o.Commit()
-	//	}
-	//}()
-
-	sql := `DELETE FROM my_chart_classify WHERE my_chart_classify_id=?`
-	_, err = o.Raw(sql, myChartClassifyId).Exec()
-	if err != nil {
-		return err
-	}
-	mappingList := make([]*MyChartClassifyMapping, 0)
-	sql = `SELECT * FROM my_chart_classify_mapping WHERE my_chart_classify_id=?`
-	_, err = o.Raw(sql, myChartClassifyId).QueryRows(&mappingList)
-
-	sql = `DELETE FROM my_chart_classify_mapping WHERE my_chart_classify_id=?`
-	_, err = o.Raw(sql, myChartClassifyId).Exec()
-	if err != nil {
-		return err
-	}
-	for _, v := range mappingList {
-		var count int
-		sql = ` SELECT COUNT(1) AS count FROM my_chart_classify_mapping WHERE my_chart_id=?`
-		err = o.Raw(sql, v.MyChartId).QueryRow(&count)
-		if err != nil {
-			return err
-		}
-		if count <= 0 {
-			sql = `DELETE FROM my_chart WHERE my_chart_id=?`
-			_, err = o.Raw(sql, v.MyChartId).Exec()
-			if err != nil {
-				return err
-			}
-		}
-	}
-	return
-}
-
-type MyChartAddReq struct {
-	ChartInfoId       int   `description:"图表id"`
-	MyChartClassifyId []int `description:"分类id,数组形式"`
-}
-
-type MyChartAddResp struct {
-	MyChartInfoId     int    `description:"图表id"`
-	MyChartClassifyId string `description:"分类id,多个用英文逗号隔开"`
-}
-
-type MyChart struct {
-	MyChartId   int       `orm:"column(my_chart_id);pk"`
-	ChartInfoId int       `description:"图表id"`
-	AdminId     int       `description:"用户id"`
-	CreateTime  time.Time `description:"创建时间"`
-	ModifyTime  time.Time `description:"修改时间"`
-}
-
-type MyChartView struct {
-	MyChartId         int       `orm:"column(my_chart_id);pk"`
-	ChartInfoId       int       `description:"图表id"`
-	AdminId           int       `description:"用户id"`
-	CreateTime        time.Time `description:"创建时间"`
-	ModifyTime        time.Time `description:"修改时间"`
-	MyChartClassifyId string
-}
-
-func AddMyChart(item *MyChart) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type MyChartClassifyMapping struct {
-	MyChartClassifyMappingId int `orm:"column(my_chart_classify_mapping_id);pk"`
-	AdminId                  int
-	MyChartId                int
-	MyChartClassifyId        int
-	CreateTime               time.Time
-	ModifyTime               time.Time
-	Sort                     float64
-}
-
-func AddMyChartClassifyMapping(item *MyChartClassifyMapping) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-func GetMyChartClassifyMapping(adminId, myChartId, myChartClassifyId int) (item *MyChartClassifyMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM my_chart_classify_mapping WHERE admin_id=? AND my_chart_id=? AND my_chart_classify_id=? `
-	err = o.Raw(sql, adminId, myChartId, myChartClassifyId).QueryRow(&item)
-	return
-}
-
-type MyChartDeleteReq struct {
-	MyChartId         int `description:"我的图表id"`
-	MyChartClassifyId int `description:"我的图表分类id"`
-}
-
-func DeleteMyChart(myChartId, myChartClassifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	if myChartClassifyId > 0 {
-		sql := `DELETE FROM my_chart_classify_mapping WHERE my_chart_id=? AND my_chart_classify_id=? `
-		_, err = o.Raw(sql, myChartId, myChartClassifyId).Exec()
-		if err != nil {
-			return
-		}
-		var count int
-		sql = ` SELECT COUNT(1) AS count FROM my_chart_classify_mapping WHERE my_chart_id=? `
-		err = o.Raw(sql, myChartId).QueryRow(&count)
-		if err != nil {
-			return
-		}
-		if count <= 0 {
-			sql = `DELETE FROM my_chart WHERE my_chart_id=? `
-			_, err = o.Raw(sql, myChartId).Exec()
-			if err != nil {
-				return
-			}
-		}
-	} else {
-		sql := `DELETE FROM my_chart WHERE my_chart_id=? `
-		_, err = o.Raw(sql, myChartId).Exec()
-		if err != nil {
-			return
-		}
-	}
-	return
-}
-
-type MyChartList struct {
-	MyChartId           int `description:"我的图表主键"`
-	ChartInfoId         int
-	ChartName           string `description:"来源名称"`
-	ChartClassifyId     int    `description:"图表分类id"`
-	SysUserId           int
-	SysUserRealName     string
-	UniqueCode          string `description:"图表唯一编码"`
-	CreateTime          time.Time
-	ModifyTime          time.Time
-	DateType            int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate           string `description:"自定义开始日期"`
-	EndDate             string `description:"自定义结束日期"`
-	IsSetName           int    `description:"设置名称"`
-	EdbInfoIds          string `description:"指标id"`
-	ChartType           int    `description:"生成样式:1:曲线图,2:季节性图"`
-	Calendar            string `description:"公历/农历"`
-	SeasonStartDate     string `description:"季节性图开始日期"`
-	SeasonEndDate       string `description:"季节性图开始日期"`
-	ChartImage          string `description:"图表图片"`
-	Sort                int    `description:"排序字段,数字越小越排前面"`
-	IsAdd               bool   `description:"true:已加入我的图库,false:未加入我的图库"`
-	MyChartClassifyName string `description:"分类名称,多个用英文逗号分割"`
-	MyChartClassifyId   string `description:"分类id,多个用英文逗号分割"`
-	EdbEndDate          string `description:"指标最新更新日期"`
-}
-
-type MyChartListResp struct {
-	Paging *paging.PagingItem
-	List   []*MyChartList
-}
-
-func GetMyChartListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyChartList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.my_chart_id,c.sort,b.* FROM my_chart AS a
-			INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
-			INNER JOIN my_chart_classify_mapping AS c ON a.my_chart_id=c.my_chart_id
-			WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	sql += " GROUP BY a.chart_info_id ORDER BY c.sort ASC LIMIT ?,? "
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
-	return
-}
-
-func GetMyChartListCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT COUNT(1) AS count FROM my_chart AS a
-			INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
-			INNER JOIN my_chart_classify_mapping AS c ON a.my_chart_id=c.my_chart_id
-			WHERE 1=1`
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-func GetMyChartMaxSort(adminId, myChartClassifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count FROM my_chart_classify_mapping WHERE 1=1 AND admin_id=? AND my_chart_classify_id=? `
-	err = o.Raw(sql, adminId, myChartClassifyId).QueryRow(&count)
-	return
-}
-
-type MoveMyChartReq struct {
-	MyChartId         int `description:"移动的,我的图表图表ID"`
-	PrevMyChartId     int `description:"移动到的位置,上一级的,我的图表ID,如果没有上一级,则传0"`
-	NextMyChartId     int `description:"移动到的位置,下一级的,我的图表ID,如果没有下一级,则传0"`
-	MyChartClassifyId int `description:"当前分类id"`
-}
-
-func MyChartMove(sort float64, adminId int, myChartId, myChartClassifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` UPDATE my_chart_classify_mapping SET sort = ?,modify_time=NOW() WHERE admin_id=? AND my_chart_id=? AND my_chart_classify_id=? `
-	_, err = o.Raw(sql, sort, adminId, myChartId, myChartClassifyId).Exec()
-	return
-}
-
-func GetMyChartMinSortByAdminId(adminId int) (item *MyChart, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart WHERE admin_id=? ORDER BY sort ASC LIMIT 1`
-	err = o.Raw(sql, adminId).QueryRow(&item)
-	return
-}
-
-type ChartRecommendListResp struct {
-	List []*ChartInfoView
-}
-
-func GetChartClassify(chartClassifyId int) (chart_classify_id string, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT GROUP_CONCAT(t.chart_classify_id) AS chart_classify_id FROM (
-			SELECT a.chart_classify_id FROM chart_classify AS a 
-			WHERE a.chart_classify_id=?
-			UNION ALL
-			SELECT a.chart_classify_id FROM chart_classify AS a 
-			WHERE a.parent_id=?
-			)AS t`
-	err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&chart_classify_id)
-	return
-}
-
-func GetRecommendChartListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartInfoView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT b.* FROM my_chart AS a
-			INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id `
-	if condition != "" {
-		sql += condition
-	}
-	sql += " ORDER BY a.create_time DESC LIMIT ?,? "
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
-	return
-}
-
-func GetMyChartListByAdminId(adminId int) (item []*MyChartView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	//sql := ` SELECT * FROM my_chart WHERE 1=1 AND admin_id=? `
-
-	sql := ` SELECT a.*,GROUP_CONCAT(c.my_chart_classify_id SEPARATOR ',') AS my_chart_classify_id FROM my_chart AS a
-			LEFT JOIN  my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
-			LEFT JOIN my_chart_classify AS c ON b.my_chart_classify_id=c.my_chart_classify_id AND b.admin_id=c.admin_id
-			WHERE 1=1 AND a.admin_id=?
-			GROUP BY a.chart_info_id `
-	_, err = o.Raw(sql, adminId).QueryRows(&item)
-	return
-}
-
-func GetMyChartSearchByCondition(condition string, pars []interface{}) (item []*MyChartList, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT a.my_chart_id,c.sort,b.*,GROUP_CONCAT(DISTINCT d.my_chart_classify_name) AS my_chart_classify_name,GROUP_CONCAT(DISTINCT d.my_chart_classify_id) AS my_chart_classify_id
-			FROM  my_chart AS a
-			INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
-			INNER JOIN my_chart_classify_mapping AS c ON a.my_chart_id=c.my_chart_id
-			INNER JOIN my_chart_classify AS d ON c.my_chart_classify_id=d.my_chart_classify_id
-			WHERE 1=1 `
-
-	if condition != "" {
-		sql += condition
-	}
-	sql += " GROUP BY a.chart_info_id ORDER BY c.sort DESC "
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-type MyChartSearchListResp struct {
-	List []*MyChartList
-}
-
-type MyChartEditReq struct {
-	MyChartId                int   `description:"我的图表主键"`
-	CurrentMyChartClassifyId int   `description:"当前分类ID"`
-	MyChartClassifyId        []int `description:"分类id,数组形式"`
-}
-
-func GetMyChartClassifyMappingCount(adminId, myChartId, myChartClassifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count
-			FROM  my_chart_classify_mapping 
-			WHERE 1=1 AND admin_id=? AND my_chart_id=? AND my_chart_classify_id=? `
-	err = o.Raw(sql, adminId, myChartId, myChartClassifyId).QueryRow(&count)
-	return
-}
-
-func DeleteMyChartClassifyMapping(adminId, myChartId, myChartClassifyId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` DELETE FROM my_chart_classify_mapping
-			WHERE admin_id=? AND my_chart_id=? AND my_chart_classify_id=? `
-	_, err = o.Raw(sql, adminId, myChartId, myChartClassifyId).Exec()
-	return
-}
-
-func GetMyChartSort(adminId, myChartClassifyId, sort int) (item *MyChartClassifyMapping, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart_classify_mapping WHERE 1=1 AND admin_id=? AND my_chart_classify_id=? `
-	if sort == 1 {
-		sql += ` ORDER BY sort DESC LIMIT 1 `
-	} else {
-		sql += ` ORDER BY sort ASC LIMIT 1 `
-	}
-	err = o.Raw(sql, adminId, myChartClassifyId).QueryRow(&item)
-	return
-}
-
-func GetMyChartByCondition(condition string, pars []interface{}) (item []*MyChartView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	//sql := ` SELECT * FROM my_chart WHERE 1=1 `
-	sql := `SELECT a.*,GROUP_CONCAT(c.my_chart_classify_id SEPARATOR ',') AS my_chart_classify_id FROM my_chart AS a
-			LEFT JOIN  my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
-			LEFT JOIN my_chart_classify AS c ON b.my_chart_classify_id=c.my_chart_classify_id AND b.admin_id=c.admin_id
-			WHERE 1=1 
-			`
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` GROUP BY a.chart_info_id  `
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetMyChartDetailByCondition(condition string, pars []interface{}) (item *MyChartView, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart WHERE 1=1 `
-	if condition != "" {
-		sql += condition
-	}
-	err = o.Raw(sql, pars).QueryRow(&item)
-	return
-}
-
-func MoveMyChartClassify(adminId, myChartId int, myChartClassifyId []int) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Begin()
-
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	classifyIdMap := make(map[int]int)
-	for _, v := range myChartClassifyId {
-		classifyIdMap[v] = v
-	}
-
-	mappingList := make([]*MyChartClassifyMapping, 0)
-	sql := `SELECT * FROM my_chart_classify_mapping WHERE admin_id=? AND my_chart_id=?`
-	_, err = o.Raw(sql, adminId, myChartId).QueryRows(&mappingList)
-	if err != nil {
-		return
-	}
-	for _, v := range mappingList {
-		if _, ok := classifyIdMap[v.MyChartClassifyId]; !ok {
-			sql := ` DELETE FROM my_chart_classify_mapping WHERE my_chart_classify_mapping_id=? `
-			_, err = o.Raw(sql, v.MyChartClassifyMappingId).Exec()
-			if err != nil {
-				return
-			}
-		}
-	}
-	//sql := `DELETE FROM my_chart_classify_mapping WHERE admin_id=? AND my_chart_id=? `
-	//_, err = o.Raw(sql, adminId, myChartId).Exec()
-	//if err != nil {
-	//	return err
-	//}
-	step := float64(65536)
-	for _, v := range myChartClassifyId {
-		var count int
-		sql := ` SELECT COUNT(1) AS count FROM my_chart_classify_mapping WHERE my_chart_id=? AND my_chart_classify_id=? `
-		err = o.Raw(sql, myChartId, v).QueryRow(&count)
-		if err != nil {
-			return
-		}
-		if count <= 0 {
-			total, err := GetMyChartMaxSort(adminId, v)
-			if err != nil {
-				return err
-			}
-			sort := (float64(total) + 1) * step
-			sql = ` INSERT INTO my_chart_classify_mapping (
-				  admin_id,
-				  my_chart_id,
-				  my_chart_classify_id,
-				  create_time,
-				  modify_time,
-				  sort )VALUES (?,?,?,NOW(),NOW(),?) `
-			_, err = o.Raw(sql, adminId, myChartId, v, sort).Exec()
-			if err != nil {
-				return err
-			}
-		}
-	}
-
-	return
-}
-
-// Update 更新分类基础信息
-func (myChartClassify *MyChartClassify) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Update(myChartClassify, cols...)
-	return
-}
-
-// GetFirstMyChartClassifyByAdminId 获取当前账号下,排序第一条的分类数据
-func GetFirstMyChartClassifyByAdminId(adminId int) (item *MyChartClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM my_chart_classify WHERE admin_id=? order by sort asc,my_chart_classify_id asc limit 1`
-	err = o.Raw(sql, adminId).QueryRow(&item)
-	return
-}
-
-// UpdateMyChartClassifySortByClassifyId 根据分类id更新排序
-func UpdateMyChartClassifySortByClassifyId(adminId, classifyId, nowSort int, updateSort string) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` update my_chart_classify set sort = ` + updateSort + ` WHERE admin_id = ? and sort > ? `
-	if classifyId > 0 {
-		sql += ` or ( my_chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
-	}
-	_, err = o.Raw(sql, adminId, nowSort).Exec()
-	return
-}

+ 0 - 25
models/data_manage/my_chart_log.go

@@ -1,25 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type MyChartLog struct {
-	MyChartLogId    int `orm:"column(my_chart_log_id);pk"`
-	MyChartId       int
-	ChartInfoId     int `description:"图表id"`
-	SysUserId       int
-	SysUserRealName string
-	CreateTime      time.Time
-	Content         string `description:"内容"`
-	Status          string `description:"状态"`
-	Method          string `description:"执行方法"`
-}
-
-func AddMyChartLog(item *MyChartLog) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	lastId, err = o.Insert(item)
-	return
-}

+ 0 - 1
models/data_manage/refresh_calculate.go

@@ -1 +0,0 @@
-package data_manage

+ 0 - 19
models/data_manage/search_keyword.go

@@ -1,19 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"time"
-)
-
-type SearchKeyword struct {
-	Id         int `orm:"column(id);pk"`
-	KeyWord    string
-	CreateTime time.Time
-}
-
-func AddSearchKeyword(item *SearchKeyword) (err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	_, err = o.Insert(item)
-	return
-}

+ 0 - 130
models/data_manage/smm_data.go

@@ -1,130 +0,0 @@
-package data_manage
-
-import (
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"strings"
-)
-
-type SmmClassify struct {
-	TypeName string `orm:"column(type_name)" description:"分类名称"`
-	TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
-}
-
-func GetSmmClassify() (items []*SmmClassify, err error) {
-	sql := `SELECT CONCAT(type_2,type_3) AS type_name,CONCAT(type_2,'#',type_3) type_code  FROM base_from_smm_index GROUP BY CONCAT(type_2,type_3) ORDER BY CONCAT(type_2,type_3) ASC `
-	o := orm.NewOrm()
-	o.Using("data")
-	o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type SmmFrequency struct {
-	Frequency string `description:"频度"`
-}
-
-func GetSmmFrequencyByClassifyId(typeCode string) (items []*GlFrequency, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	var type2, type3 string
-	if strings.Contains(typeCode, "#") {
-		typeArr := strings.Split(typeCode, "#")
-		type2 = typeArr[0]
-		type3 = typeArr[1]
-	} else {
-		type2 = typeCode
-	}
-
-	var condition string
-	var pars []interface{}
-
-	if type2 != "" {
-		condition += ` AND type_2=? `
-		pars = append(pars, type2)
-	}
-
-	if type3 != "" {
-		condition += ` AND type_3=? `
-		pars = append(pars, type3)
-	}
-
-	sql := ` SELECT frequency FROM base_from_smm_index WHERE 1=1  `
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` GROUP BY frequency ORDER BY frequency ASC `
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-type SmmIndex struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
-	Interface          string
-	Name               string
-	IndexCode          string
-	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
-	Frequency          string
-	Unit               string
-	ApiStartTime       string
-	ApiUpdateTime      string
-	StartTime          string
-	FinishTime         string
-	CreateTime         string
-	ModifyTime         string
-}
-
-func GetSmmIndex(condition string, pars interface{}) (items []*SmmIndex, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT * FROM base_from_smm_index WHERE 1=1  `
-	if condition != "" {
-		sql += condition
-	}
-	sql += `ORDER BY INDEX_CODE ASC`
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-type SmmIndexList struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
-	Interface          string
-	Name               string
-	IndexCode          string
-	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
-	Frequency          string
-	Unit               string
-	ApiStartTime       string
-	ApiUpdateTime      string
-	StartTime          string
-	FinishTime         string
-	ModifyTime         string
-	DataList           []*SmmIndexData
-	Paging             *paging.PagingItem `description:"分页数据"`
-}
-
-type SmmIndexData struct {
-	Value    string `orm:"column(value)" description:"日期"`
-	DataTime string `orm:"column(data_time)" description:"值"`
-}
-
-func GetSmmIndexData(indexCode string, startSize, pageSize int) (items []*SmmIndexData, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT *  FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
-	_, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
-	return
-}
-
-func GetSmmIndexDataCount(indexCode string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := ` SELECT COUNT(1) AS count  FROM base_from_smm_data WHERE index_code=? `
-	err = o.Raw(sql, indexCode).QueryRow(&count)
-	return
-}

+ 5 - 34
models/db.go

@@ -6,7 +6,7 @@ import (
 	"hongze/hongze_chart_lib/utils"
 	"time"
 
-	"github.com/rdlucklib/rdluck_tools/orm"
+	"github.com/beego/beego/v2/client/orm"
 )
 
 func init() {
@@ -32,41 +32,12 @@ func init() {
 	edb_db, _ := orm.GetDB("edb")
 	edb_db.SetConnMaxLifetime(10 * time.Minute)
 
+	orm.Debug = true
+	orm.DebugLog = orm.NewLog(utils.Binlog)
+
 	//注册对象
 	orm.RegisterModel(
-		new(data_manage.EdbClassify),
 		new(data_manage.EdbInfo),
-		new(data_manage.EdbDataThs),
-		new(data_manage.EdbDataWind),
-		new(data_manage.EdbDataPb),
-		new(data_manage.ChartClassify),
-		new(data_manage.ChartInfo),
-		new(data_manage.ChartEdbMapping),
-		new(data_manage.ManualUserClassify),
-		new(data_manage.EdbdataClassify),
-		new(data_manage.ManualUser),
-		new(data_manage.EdbInfoCalculate),
-		new(data_manage.EdbDataCalculate),
-		new(data_manage.EdbInfoCalculateLjzzy),
-		new(data_manage.EdbInfoCalculateTbz),
-		new(data_manage.EdbInfoCalculateTcz),
-		new(data_manage.EdbInfoCalculateNszydpjjs),
-		new(data_manage.SearchKeyword),
-		new(data_manage.EdbInfoCalculateHbz),
-		new(data_manage.EdbInfoCalculateHcz),
-		new(data_manage.EdbInfoCalculateBp),
-		new(data_manage.BaseFromSmm),
-		new(data_manage.BaseFromSmmIndex),
-		new(data_manage.BaseFromSmmData),
-		new(data_manage.MyChartClassify),
-		new(data_manage.MyChart),
-		new(data_manage.MyChartClassifyMapping),
-		new(data_manage.ChartInfoLog),
-		new(data_manage.EdbInfoLog),
-		new(data_manage.MyChartLog),
-		new(data_manage.EdbInfoCalculateMapping),
-		new(data_manage.EdbDataCalculateZjpj),    //直接拼接
-		new(data_manage.EdbDataCalculateLjztbpj), //累计同比值拼接
-		new(ShareChartRefreshLog),	//分享图表刷新日志表
+		new(ShareChartRefreshLog), //分享图表刷新日志表
 	)
 }

+ 2 - 0
models/edb_data_base.go

@@ -56,6 +56,8 @@ func GetEdbDataTableName(source int) (tableName string) {
 		tableName = "edb_data_calculate_ljztbpj"
 	case utils.DATA_SOURCE_LT:
 		tableName = "edb_data_lt"
+	case utils.DATA_SOURCE_COAL:
+		tableName = "edb_data_coal"
 	default:
 		tableName = ""
 	}

+ 7 - 8
models/share_chart_refresh_log.go

@@ -1,22 +1,21 @@
 package models
 
 import (
-	"github.com/rdlucklib/rdluck_tools/orm"
+	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
 // ShareChartRefreshLog 分享图表的日志
 type ShareChartRefreshLog struct {
-	Id     int    `orm:"column(id);pk"`
-	Ip       string `description:"来源ip"`
-	ChartId int    `description:"图表分类id"`
-	CreateTime      time.Time
+	Id         int    `orm:"column(id);pk"`
+	Ip         string `description:"来源ip"`
+	ChartId    int    `description:"图表分类id"`
+	CreateTime time.Time
 }
 
 // AddShareChartRefreshLog 添加日志
 func AddShareChartRefreshLog(item *ShareChartRefreshLog) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
+	o := orm.NewOrmUsingDB("data")
 	lastId, err = o.Insert(item)
 	return
-}
+}

+ 0 - 1318
models/target.go

@@ -1,1318 +0,0 @@
-package models
-
-import (
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/orm"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"sort"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type DataList struct {
-	TradeCode    string  `orm:"column(TRADE_CODE)" description:"指标编码"`
-	SecName      string  `orm:"column(SEC_NAME)" description:"指标名称"`
-	Unit         string  `orm:"column(UNIT)" description:"单位"`
-	Remark       string  `orm:"column(REMARK)" description:"备注"`
-	Frequency    string  `description:"频度"`
-	ClassifyId   int     `description:"分类id"`
-	ClassifyName string  `description:"分类名称"`
-	Dt           string  `orm:"column(DT)" description:"录入日期"`
-	Close        float64 `orm:"column(CLOSE)" description:"录入值"`
-	ModifyTime   string  `description:"修改时间"`
-}
-
-type DataListResp struct {
-	List   []*DataList
-	Paging *paging.PagingItem `description:"分页数据"`
-}
-
-func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
-	sql := `select a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE,c.modify_time FROM edbdata AS c
-                inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
-                left join edbdata_classify AS b ON a.classify_id=b.classify_id
-                where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-	if condition != "" {
-		sql += condition
-	}
-	sql += ` order by c.DT desc limit ?,? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
-	return
-}
-
-func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
-	sql := ` select count(1) as count FROM edbdata AS c
-                    inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE    
-                    left join edbdata_classify AS b ON a.classify_id=b.classify_id
-                    where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
-	if condition != "" {
-		sql += condition
-	}
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, pars).QueryRow(&count)
-	return
-}
-
-type DataAddReq struct {
-	TradeCode  string `description:"指标唯一编码"`
-	CreateDate string `description:"创建日期"`
-	Close      string `description:"录入值"`
-}
-
-type Edbdata struct {
-	TradeCode  string    `orm:"column(TRADE_CODE);pk" description:"指标编码"`
-	Dt         string    `orm:"column(DT)" description:"日期"`
-	Close      string    `orm:"column(CLOSE)" description:"值"`
-	ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
-}
-
-func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
-	sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
-	return
-}
-
-func AddEdbdata(item *Edbdata) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	lastId, err = o.Insert(item)
-	return
-}
-
-type DataEditReq struct {
-	TradeCode     string      `description:"指标唯一编码"`
-	CreateDate    string      `description:"创建日期"`
-	Close         interface{} `description:"录入值"`
-	OldCreateDate string      `description:"旧的录入日期"`
-}
-
-// BatchDataEditReq 批量修改指标
-type BatchDataEditReq struct {
-	OldCreateDate string        `description:"旧的录入日期"`
-	CreateDate    string        `description:"新的录入日期"`
-	List          []DataEditReq `description:"需要修改的数据"`
-}
-
-//编辑数据
-func EditEdbdata(item *Edbdata) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
-	_, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
-	return
-}
-
-type EdbdataDeleteRecord struct {
-	Id         int       `orm:"column(id);pk"`
-	TradeCode  string    `orm:"column(TRADE_CODE)" description:"指标编码"`
-	Dt         string    `orm:"column(DT)" description:"日期"`
-	Close      string    `orm:"column(CLOSE)" description:"值"`
-	ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
-	CreateTime time.Time
-	SysUserId  int
-}
-
-func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	lastId, err = o.Insert(item)
-	return
-}
-
-//删除数据
-func DeleteEdbData(tradeCode, dt string) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
-	_, err = o.Raw(sql, tradeCode, dt).Exec()
-	return
-}
-
-type Edbinfo struct {
-	TradeCode    string `orm:"column(TRADE_CODE);pk" description:"指标code"`
-	SecName      string `orm:"column(SEC_NAME);" description:"指标名称"`
-	Unit         string `orm:"column(UNIT);" description:"单位"`
-	Remark       string `orm:"column(REMARK);" description:"备注"`
-	Frequency    string `description:"频度"`
-	ClassifyId   int    `description:"分类id"`
-	ClassifyName string `description:"分类名称"`
-	CreateDate   string `description:"创建时间"`
-	UserId       int    `description:"录入用户id"`
-	UserName     string `description:"录入用户名称"`
-	NoticeTime   string `description:"通知时间"`
-	Mobile       string `description:"录入者手机号"`
-}
-
-func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, roleType int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ``
-	if mobile != "" && roleType == 1 {
-		sql = `SELECT COUNT(1) AS count FROM edbinfo AS a 
-             INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-
-		if condition != "" {
-			sql += condition
-		}
-		err = o.Raw(sql, mobile, pars).QueryRow(&count)
-	} else {
-		sql := `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-
-		if condition != "" {
-			sql += condition
-		}
-		err = o.Raw(sql, pars).QueryRow(&count)
-	}
-	return
-}
-
-func GetEdbinfoList(condition string, pars []interface{}, startSize, pageSize int, mobile string, roleType int) (items []*Edbinfo, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ``
-	if mobile != "" && roleType == 1 {
-		sql = ` SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
-                    LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-                    INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
-                    WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-		if condition != "" {
-			sql += condition
-		}
-		sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
-		_, err = o.Raw(sql, mobile, pars, startSize, pageSize).QueryRows(&items)
-	} else {
-		sql = `SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
-                     LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
-                     WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-		if condition != "" {
-			sql += condition
-		}
-		sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
-		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
-	}
-	return
-}
-
-// EdbParamsInfo 指标数据结构体
-type EdbParamsInfo struct {
-	Unit      string `orm:"column(UNIT);" description:"单位"`
-	Frequency string `orm:"column(frequency);" description:"单位"`
-}
-
-// GetEdbUnitList 获取指标单位
-func GetEdbUnitList() (items []*EdbParamsInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT UNIT from edbinfo group by UNIT`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-// GetEdbFrequencyList 获取指标频度
-func GetEdbFrequencyList(classifyId, userId int) (items []*EdbParamsInfo, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT frequency from edbinfo a 
-join edbdata b on a.TRADE_CODE=b.TRADE_CODE
- where classify_id = ? `
-	if userId > 0 {
-		sql += ` and a.user_id = ` + fmt.Sprint(userId) + ` `
-	}
-	sql += ` group by a.frequency`
-	_, err = o.Raw(sql, classifyId).QueryRows(&items)
-	return
-}
-
-type TargetListResp struct {
-	List   []*Edbinfo
-	Paging *paging.PagingItem `description:"分页数据"`
-}
-
-type EdbinfoAddReq struct {
-	SecName    string `description:"指标名称"`
-	Unit       string `description:"单位"`
-	Frequency  string `description:"频度"`
-	ClassifyId int    `description:"分类id"`
-	NoticeTime string `description:"通知时间"`
-}
-
-//获取指标最大trade_code
-func GetMaxTradeCode() (max_trade_code string, err error) {
-	sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' "
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql).QueryRow(&max_trade_code)
-	return
-}
-
-func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
-	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, secName).QueryRow(&item)
-	return
-}
-
-func GetEdbinfoByTradeCode(tradeCode string) (item *Edbinfo, err error) {
-	sql := `SELECT * FROM edbinfo WHERE TRADE_CODE=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode).QueryRow(&item)
-	return
-}
-
-func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int) (err error) {
-	sql := `INSERT INTO edbinfo(TRADE_CODE, SEC_NAME,UNIT, REMARK,frequency, classify_id,notice_time,user_id) 
-			VALUES(?,?,?,?,?,?,?,?) `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, tradeCode, secName, unit, remark, frequency, classifyId, noticeTime, userId).Exec()
-	return
-}
-
-func AddEdbinfoUser(tradeCode, mobile string) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
-	_, err = o.Raw(sql, tradeCode, mobile).Exec()
-	return
-}
-
-type EdbinfoEditReq struct {
-	TradeCode  string `description:"指标code"`
-	SecName    string `description:"指标名称"`
-	Unit       string `description:"单位"`
-	Frequency  string `description:"频度"`
-	ClassifyId int    `description:"分类id"`
-	NoticeTime string `description:"通知时间"`
-}
-
-func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
-	sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
-	return
-}
-
-func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
-	where := ""
-	if keyWord != "" {
-		where = `AND SEC_NAME LIKE '%` + keyWord + `%'`
-	}
-	sql := `SELECT * FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' AND classify_id>0 AND classify_id=? `
-	sql += where
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, classifyId).QueryRows(&items)
-	return
-}
-
-type SearchTargetListResp struct {
-	List []*Edbinfo
-}
-
-type EdbdataClassify struct {
-	ClassifyId   int
-	ClassifyName string
-	ParentId     int
-	EdbInfoTotal int
-}
-
-func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
-	sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, classifyName).QueryRow(&item)
-	return
-}
-
-type EdbdataClassifyList struct {
-	ClassifyId   int
-	ClassifyName string
-	ParentId     int
-	Child        []*EdbdataClassify
-}
-
-func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
-	var newItems []*EdbdataClassifyList
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
-	_, err = o.Raw(sql).QueryRows(&newItems)
-	if err != nil {
-		return
-	}
-	classifyLen := len(newItems)
-
-	for i := 0; i < classifyLen; i++ {
-		var childItems []*EdbdataClassify
-		parentId := newItems[i].ClassifyId
-		childSql := ``
-		if userId > 0 {
-			userClassifyList, _ := GetManualUserClassify(int(userId))
-			var userIdArr []string
-			for _, v := range userClassifyList {
-				userIdArr = append(userIdArr, strconv.Itoa(v.ClassifyId))
-			}
-
-			userIdStr := strings.Join(userIdArr, ",")
-			if userIdStr != "" {
-				childSql = "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a WHERE a.is_show=1 and a.classify_id IN(" + userIdStr + ") AND parent_id=? ORDER BY a.create_time ASC "
-				_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
-			}
-		} else {
-			childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 and parent_id=? ORDER BY create_time ASC "
-			_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
-		}
-		if err != nil {
-			return
-		}
-		newItems[i].Child = childItems
-	}
-	for _, v := range newItems {
-		childLen := len(v.Child)
-		if childLen > 0 {
-			items = append(items, v)
-		}
-	}
-	return
-}
-
-type ManualUserClassify struct {
-	ManualUserClassifyId int `orm:"column(manual_user_classify_id);pk"`
-	AdminId              int
-	ClassifyId           int
-	CreateTime           time.Time
-}
-
-func GetManualUserClassify(sysUserId int) (list []*ManualUserClassify, err error) {
-	o := orm.NewOrm()
-	o.Using("data")
-	sql := `SELECT * FROM manual_user_classify WHERE admin_id=? `
-	_, err = o.Raw(sql, sysUserId).QueryRows(&list)
-	return
-}
-
-type EdbdataClassifyResp struct {
-	List []*EdbdataClassifyList
-}
-
-func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
-	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, secName).QueryRow(&item)
-	return
-}
-
-//更新指标数据信息
-func (edbinfo *Edbinfo) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Update(edbinfo, cols...)
-	return
-}
-
-func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
-	sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, classifyId, tradeCode).Exec()
-	return
-}
-
-func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
-	sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
-	return
-}
-
-func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
-	sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
-	return
-}
-
-func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
-	sql := `UPDATE  edbdata SET CLOSE=?,modify_time=NOW() WHERE  TRADE_CODE=? AND DT=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, close, tradeCode, dt).Exec()
-	return
-}
-
-func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
-	sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, tradeCode, dt, close).Exec()
-	return
-}
-
-type EdbdataImportResp struct {
-	Status       int
-	Msg          string
-	SuccessCount int
-	FailCount    int
-}
-
-type DataListForExport struct {
-	TradeCode    string `orm:"column(TRADE_CODE)" description:"指标code"`
-	SecName      string `orm:"column(SEC_NAME)" description:"指标名称"`
-	Unit         string `orm:"column(UNIT)" description:"单位"`
-	Frequency    string `description:"频度"`
-	ClassifyId   int    `description:"分类id"`
-	NoticeTime   string `description:"通知时间"`
-	ClassifyName string
-	Dt           string  `orm:"column(DT)" description:"日期"`
-	Close        float64 `orm:"column(CLOSE)" description:"值"`
-}
-
-func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
-	where := ``
-	var pars []interface{}
-	if keyWord != "" {
-		where = ` AND SEC_NAME LIKE '%` + keyWord + `%`
-	}
-	if startDate != "" {
-		where += ` AND create_date>=? `
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		where += ` AND create_date<=? `
-		pars = append(pars, endDate)
-	}
-	if frequency != "" {
-		where += ` AND frequency=? `
-		pars = append(pars, frequency)
-	}
-	if classifyId > 0 {
-		where += ` AND classify_id=? `
-		pars = append(pars, classifyId)
-	}
-
-	sql := ` SELECT a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE FROM edbdata AS c
-                INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
-                LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-                WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
-	if where != "" {
-		sql += where
-	}
-	sql = sql + " ORDER BY c.DT DESC "
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-type DataDeleteReq struct {
-	TradeCode  string `description:"指标唯一编码"`
-	CreateDate string `description:"数据录入日期"`
-}
-
-func DataDelete(tradeCode, createDate, close string, modifyTime time.Time, sysUserId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-	recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id) 
-                 VALUES(?,?,?,?,?,?)`
-	_, err = o.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
-	sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
-	_, err = o.Raw(sql, tradeCode, createDate).Exec()
-	return
-}
-
-func GetTargetInfoCount(tradeCode string) (count int, err error) {
-	sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
-           INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
-           WHERE a.TRADE_CODE=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode).QueryRow(&count)
-	return
-}
-
-type TargetDeleteReq struct {
-	TradeCode string `description:"指标唯一编码"`
-}
-
-func TargetDelete(tradeCode string) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Begin()
-	defer func() {
-		if err != nil {
-			o.Rollback()
-		} else {
-			o.Commit()
-		}
-	}()
-
-	sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
-	_, err = o.Raw(sql, tradeCode).Exec()
-
-	sql = " DELETE FROM edbdata WHERE TRADE_CODE = ? "
-	_, err = o.Raw(sql, tradeCode).Exec()
-
-	return
-}
-
-type Researcher struct {
-	AdminId     int    `description:"系统用户id"`
-	AdminName   string `description:"系统用户名称"`
-	RealName    string `description:"系统用户姓名"`
-	Role        string `description:"系统用户角色"`
-	Mobile      string `description:"手机号"`
-	TargetCount int    `description:"指标数量"`
-}
-
-type ResearcherListResp struct {
-	List []*Researcher
-}
-
-func GetResearcherEntry() (items []*Researcher, err error) {
-	sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
-	o := orm.NewOrm()
-	_, err = o.Raw(sql).QueryRows(&items)
-	researchLen := len(items)
-	edbO := orm.NewOrm()
-	edbO.Using("edb")
-	for i := 0; i < researchLen; i++ {
-		var count int
-		mobile := items[i].Mobile
-		sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM  edbinfo_user AS a
-            INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
-            WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
-		err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
-		items[i].TargetCount = count
-	}
-	return
-}
-
-func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error) {
-	sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE  role_type=1 `
-	if mobile != "" {
-		sql += ` AND mobile IN(` + mobile + `)`
-	}
-	o := orm.NewOrm()
-	_, err = o.Raw(sql).QueryRows(&items)
-	researchLen := len(items)
-	edbO := orm.NewOrm()
-	edbO.Using("edb")
-	for i := 0; i < researchLen; i++ {
-		var count int
-		mobile := items[i].Mobile
-		sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM  edbinfo_user AS a
-            INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
-            WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
-		err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
-		items[i].TargetCount = count
-	}
-	return
-}
-
-type EdbinfoItems struct {
-	TradeCode    string `orm:"column(TRADE_CODE);pk" description:"指标code"`
-	SecName      string `orm:"column(SEC_NAME);" description:"指标名称"`
-	Unit         string `orm:"column(UNIT);" description:"单位"`
-	Remark       string `orm:"column(REMARK);" description:"备注"`
-	Frequency    string `description:"频度"`
-	ClassifyId   int    `description:"分类id"`
-	ClassifyName string `description:"分类名称"`
-	CreateDate   string `description:"创建时间"`
-	UserId       int    `description:"录入用户id"`
-	NoticeTime   string `description:"通知时间"`
-	Mobile       string `description:"录入者手机号"`
-	ModifyDate   string `description:"待更新日期"`
-	Status       string `description:"状态:未完成/完成"`
-}
-
-type TargetItemsResp struct {
-	List SortEdbInfo
-}
-
-type SortEdbInfo []EdbinfoItems
-
-func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
-	var items []*EdbinfoItems
-	o := orm.NewOrm()
-	o.Using("edb")
-	//sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
-
-	sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a 
-            WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
-             `
-	if classifyId > 0 {
-		sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
-	}
-	sql += ` GROUP BY a.TRADE_CODE `
-
-	//if classifyId > 0 {
-	//	sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
-	//        WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
-	//         GROUP BY a.TRADE_CODE `
-	//}
-
-	sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk )  COLLATE gbk_chinese_ci ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
-	if err != nil {
-		return
-	}
-	itemsLen := len(items)
-	nowWeek := time.Now().Weekday().String()
-
-	fmt.Println(nowWeek)
-	finishEdbInfo := SortEdbInfo{}
-	unFinishEdbInfo := SortEdbInfo{}
-
-	for i := 0; i < itemsLen; i++ {
-		noticeTime := items[i].NoticeTime
-		frequency := items[i].Frequency
-		tradeCode := items[i].TradeCode
-		if noticeTime != "" {
-			if frequency == "周度" {
-				noticeArr := strings.Split(noticeTime, " ")
-				noticeWeek := noticeArr[0]
-				fmt.Println(noticeWeek)
-				addDay := 0
-
-				if nowWeek == "Sunday" {
-					if noticeWeek == "周日" {
-						addDay = 0
-					} else if noticeWeek == "周一" {
-						addDay = 1
-					} else if noticeWeek == "周二" {
-						addDay = 2
-					} else if noticeWeek == "周三" {
-						addDay = 3
-					} else if noticeWeek == "周四" {
-						addDay = 4
-					} else if noticeWeek == "周五" {
-						addDay = 5
-					} else if noticeWeek == "周六" {
-						addDay = 6
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Monday" {
-					if noticeWeek == "周日" {
-						addDay = 6
-					} else if noticeWeek == "周一" {
-						addDay = 0
-					} else if noticeWeek == "周二" {
-						addDay = 1
-					} else if noticeWeek == "周三" {
-						addDay = 2
-					} else if noticeWeek == "周四" {
-						addDay = 3
-					} else if noticeWeek == "周五" {
-						addDay = 4
-					} else if noticeWeek == "周六" {
-						addDay = 5
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Tuesday" {
-					if noticeWeek == "周日" {
-						addDay = 5
-					} else if noticeWeek == "周一" {
-						addDay = 6
-					} else if noticeWeek == "周二" {
-						addDay = 0
-					} else if noticeWeek == "周三" {
-						addDay = 1
-					} else if noticeWeek == "周四" {
-						addDay = 2
-					} else if noticeWeek == "周五" {
-						addDay = 3
-					} else if noticeWeek == "周六" {
-						addDay = 4
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Wednesday" {
-					if noticeWeek == "周日" {
-						addDay = 4
-					} else if noticeWeek == "周一" {
-						addDay = 5
-					} else if noticeWeek == "周二" {
-						addDay = 6
-					} else if noticeWeek == "周三" {
-						addDay = 0
-					} else if noticeWeek == "周四" {
-						addDay = 1
-					} else if noticeWeek == "周五" {
-						addDay = 2
-					} else if noticeWeek == "周六" {
-						addDay = 3
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Thursday" {
-					if noticeWeek == "周日" {
-						addDay = 3
-					} else if noticeWeek == "周一" {
-						addDay = 4
-					} else if noticeWeek == "周二" {
-						addDay = 5
-					} else if noticeWeek == "周三" {
-						addDay = 6
-					} else if noticeWeek == "周四" {
-						addDay = 0
-					} else if noticeWeek == "周五" {
-						addDay = 1
-					} else if noticeWeek == "周六" {
-						addDay = 2
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Friday" {
-					if noticeWeek == "周日" {
-						addDay = 2
-					} else if noticeWeek == "周一" {
-						addDay = 3
-					} else if noticeWeek == "周二" {
-						addDay = 4
-					} else if noticeWeek == "周三" {
-						addDay = 5
-					} else if noticeWeek == "周四" {
-						addDay = 6
-					} else if noticeWeek == "周五" {
-						addDay = 0
-					} else if noticeWeek == "周六" {
-						addDay = 1
-					} else {
-						addDay = 0
-					}
-				} else if nowWeek == "Saturday" {
-					if noticeWeek == "周日" {
-						addDay = 1
-					} else if noticeWeek == "周一" {
-						addDay = 2
-					} else if noticeWeek == "周二" {
-						addDay = 3
-					} else if noticeWeek == "周三" {
-						addDay = 4
-					} else if noticeWeek == "周四" {
-						addDay = 5
-					} else if noticeWeek == "周五" {
-						addDay = 6
-					} else if noticeWeek == "周六" {
-						addDay = 0
-					} else {
-						addDay = 0
-					}
-				}
-
-				modifyDate := time.Now().AddDate(0, 0, addDay)
-				modifyDateStr := modifyDate.Format(utils.FormatDate)
-				items[i].ModifyDate = modifyDateStr
-
-				modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
-
-				fmt.Println("addDay:", addDay)
-				fmt.Println("modifyDateEndStr:", modifyDateEndStr)
-
-				count := 0
-				sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
-				err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
-				if err != nil {
-					return nil, err
-				}
-				if count > 0 {
-					items[i].Status = "完成"
-					finishEdbInfo = append(finishEdbInfo, *items[i])
-				} else {
-					items[i].Status = "未完成"
-					unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
-				}
-			} else if frequency == "日度" {
-				items[i].Status = "完成"
-				finishEdbInfo = append(finishEdbInfo, *items[i])
-			} else if frequency == "月度" {
-				myYear := time.Now().Year()
-				myMonth := time.Now().Format("01")
-				startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
-				count := 0
-				sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
-				err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
-				if err != nil {
-					return nil, err
-				}
-				if noticeTime != "" {
-					var modifyDateStr string
-					strArr := strings.Split(noticeTime, "日")
-					myYear := time.Now().Year()
-					myMonth := time.Now().Format("01")
-					modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
-					items[i].ModifyDate = modifyDateStr
-				}
-				if count > 0 {
-					items[i].Status = "完成"
-					finishEdbInfo = append(finishEdbInfo, *items[i])
-				} else {
-					items[i].Status = "未完成"
-					unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
-				}
-			} else {
-				items[i].Status = "完成"
-				finishEdbInfo = append(finishEdbInfo, *items[i])
-			}
-		} else {
-			if frequency == "月度" {
-				myYear := time.Now().Year()
-				myMonth := time.Now().Format("01")
-				startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
-				count := 0
-				sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
-				err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
-				if err != nil {
-					return nil, err
-				}
-				if count > 0 {
-					items[i].Status = "完成"
-					finishEdbInfo = append(finishEdbInfo, *items[i])
-				} else {
-					items[i].Status = "未完成"
-					unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
-				}
-			} else {
-				items[i].Status = "完成"
-				finishEdbInfo = append(finishEdbInfo, *items[i])
-			}
-		}
-	}
-	sort.Sort(SortByModifyDate{finishEdbInfo})
-	sort.Sort(SortByModifyDate{unFinishEdbInfo})
-	lastItems = append(lastItems, unFinishEdbInfo...)
-	lastItems = append(lastItems, finishEdbInfo...)
-	return
-}
-
-//获取此 slice 的长度
-func (p SortEdbInfo) Len() int { return len(p) }
-
-// 根据元素的状态降序排序
-func (p SortEdbInfo) Less(i, j int) bool {
-	return p[i].Status > p[j].Status
-}
-
-// 交换数据
-func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
-
-// 嵌套结构体  将继承 SortEdbInfo 的所有属性和方法
-// 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
-type SortByStatus struct{ SortEdbInfo }
-
-// 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
-func (p SortByStatus) Less(i, j int) bool {
-	return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
-}
-
-type SortByModifyDate struct{ SortEdbInfo }
-
-// 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
-func (p SortByModifyDate) Less(i, j int) bool {
-	return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
-}
-
-type DataCheckResp struct {
-	Status int    `description:"状态:1:该日期已存在数据,是否确认修改?,0:数据不存在"`
-	Close  string `description:"值"`
-}
-
-type TargetCheckResp struct {
-	Status int `description:"状态:1:该指标有关联数据,请先删除数据,0:指标不存在关联数据,可直接删除"`
-}
-
-type EdbdataExportList struct {
-	TradeCode    string `orm:"column(TRADE_CODE);" description:"指标code"`
-	SecName      string `orm:"column(SEC_NAME);" description:"指标名称"`
-	Unit         string `orm:"column(UNIT);" description:"单位"`
-	Remark       string `orm:"column(REMARK);" description:"备注"`
-	Frequency    string `description:"频度"`
-	ClassifyId   int    `description:"分类id"`
-	ClassifyName string `description:"分类名称"`
-	CreateDate   string `description:"创建时间"`
-	Dt           string `orm:"column(Dt);" description:"最新一次录入时间"`
-}
-
-func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataExportList, err error) {
-	//sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt
-	//	        FROM edbdata AS c
-	//	        INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
-	//	        INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
-	//	        LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-	//	        WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-	sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
-		        FROM edbdata AS c
-		        INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
-		        LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-		        WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
-	if condition != "" {
-		sql += condition
-	}
-	sql += " GROUP BY a.TRADE_CODE ORDER BY a.TRADE_CODE ASC "
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, pars).QueryRows(&items)
-	return
-}
-
-type EdbdataList struct {
-	Dt string `orm:"column(DT);" description:"录入时间"`
-}
-
-func GetEdbdataList(tradeCode string) (items []*EdbdataList, err error) {
-	sql := ` SELECT  DT FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `)  GROUP BY DT ORDER BY DT DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type EdbdataItem struct {
-	TradeCode string  `orm:"column(TRADE_CODE);" description:"指标code"`
-	Dt        string  `orm:"column(DT);" description:"最新一次录入时间"`
-	Close     float64 `orm:"column(CLOSE);" description:"值"`
-}
-
-func GetEdbdataValueByTradeCode(tradeCode, dt string) (item *EdbdataItem, err error) {
-	sql := ` SELECT  TRADE_CODE,DT,CLOSE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
-	return
-}
-
-func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
-	sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Raw(sql, parentId).QueryRows(&items)
-	return
-}
-
-type LzPriceClassify struct {
-	ProductName string
-}
-
-func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
-	sql := ` SELECT product_name  FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type Longzhongpriceinfo struct {
-	LongzhongpriceinfoId int `orm:"column(longzhongpriceinfo_id);pk"`
-	Standard             string
-	ModelName            string
-	Unit                 string
-	AreaName             string
-	PriceType            string
-	Memo                 string
-	PriceId              string
-	ProductName          string
-	InfoType             string
-	InfoTypeRemark       string
-	MarketName           string
-	ManufactureName      string
-}
-
-func GetLongzhongpriceinfoByClassifyName(productName string) (items []*Longzhongpriceinfo, err error) {
-	sql := `SELECT * FROM longzhongpriceinfo WHERE product_name=? ORDER BY longzhongpriceinfo_id ASC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, productName).QueryRows(&items)
-	return
-}
-
-func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT MAX(t.num) AS count FROM (
-				SELECT COUNT(1) AS num  FROM longzhongpriceinfo AS a
-				INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
-				WHERE a.product_name=?
-				GROUP BY a.product_name
-			)AS t `
-	err = o.Raw(sql, productName).QueryRow(&count)
-	return
-}
-
-type LongzhongpricedataItems struct {
-	LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
-	LongzhongpriceinfoId int
-	PriceDate            string
-	Memo                 string
-	Price                float64
-	CnyPrice             float64
-	ZsyPrice             float64
-	ZshPrice             float64
-	LowPrice             float64
-	HighPrice            float64
-	RisePrice            float64
-	TonPrice             float64
-	PriceType            string
-	UpdateDate           string
-}
-
-func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := ` SELECT DISTINCT a.longzhongpriceinfo_id,a.price_date,a.memo,a.price,a.cny_price,a.zsy_price,a.zsh_price,a.low_price,a.high_price,a.rise_price,a.ton_price,a.price_type,a.update_date  
-			 FROM longzhongpricedata AS a
-			 WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
-	_, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
-	return
-}
-
-func GetLzSurveyClassify() (items []*LzPriceClassify, err error) {
-	sql := ` SELECT breed_name AS product_name  FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type LongzhongSurveyProduct struct {
-	SurveyProductId      int `orm:"column(survey_product_id);pk"`
-	ProjectQuotaId       int64
-	BreedId              string
-	BreedName            string
-	QuotaId              string
-	QuotaName            string
-	UnitId               string
-	UnitName             string
-	SampleType           int64
-	SampleId             string
-	SampleName           string
-	DeviceId             string
-	Device               string
-	ProductCraftId       string
-	ProductCraft         string
-	ProductLine          string
-	InputMode            int64
-	Frequency            int64
-	InputValue           string
-	TaskShouldFinishTime int
-	CustomId             string
-	CustomType           int64
-	Custom               string
-	QuotaSampleId        int64
-	StartDate            string
-	EndDate              string
-	LzCode               string
-}
-
-func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
-	sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql, productName).QueryRows(&items)
-	return
-}
-
-// EdbInfoItem
-type EdbInfoItem struct {
-	TradeCode    string     `orm:"column(TRADE_CODE);pk" description:"指标code"`
-	SecName      string     `orm:"column(SEC_NAME);" description:"指标名称"`
-	Unit         string     `orm:"column(UNIT);" description:"单位"`
-	Remark       string     `orm:"column(REMARK);" description:"备注"`
-	Frequency    string     `description:"频度"`
-	ClassifyId   int        `description:"分类id"`
-	ClassifyName string     `description:"分类名称"`
-	CreateDate   string     `description:"创建时间"`
-	UserId       int        `description:"录入用户id"`
-	NoticeTime   string     `description:"通知时间"`
-	Mobile       string     `description:"录入者手机号"`
-	ModifyDate   string     `description:"待更新日期"`
-	Status       string     `description:"状态:未完成/完成"`
-	DataList     []*Edbdata `description:"指标数据列表"`
-}
-
-// GetTargetItemList 获取指标列表数据
-func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCode string, classifyIdStrList []string) (items []*EdbInfoItem, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-
-	sql := ` SELECT a.*,'' modify_date,'' STATUS FROM edbinfo AS a `
-	if edbShowType != 0 {
-		sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a 
-left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
-	}
-	sql += ` WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
-
-	//如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
-	if len(classifyIdStrList) <= 0 {
-		return
-	}
-	if len(classifyIdStrList) > 0 {
-		sql += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `)  `
-	}
-	if classifyId > 0 {
-		sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ` `
-	}
-	//频度
-	if frequency != "" {
-		sql += ` AND a.frequency="` + frequency + `" `
-	}
-	//关键字
-	if keyword != "" {
-		sql += ` AND (a.SEC_NAME like "%` + keyword + `%"  or a.TRADE_CODE like "%` + keyword + `%" )`
-	}
-	//指定指标
-	if tradeCode != "" {
-		sql += ` AND a.TRADE_CODE = "` + tradeCode + `" `
-	}
-	//指标里面是否有数据
-	switch edbShowType {
-	case 1:
-		sql += ` AND b.CLOSE is not null `
-	case 2:
-		sql += ` AND b.CLOSE is null `
-	}
-	sql += ` GROUP BY a.TRADE_CODE `
-
-	sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk )  COLLATE gbk_chinese_ci ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-
-}
-
-// GetEdbDataListByCodes 通过指标ID获取所有数据
-func GetEdbDataListByCodes(tradeCode string) (items []*Edbdata, err error) {
-	sql := ` SELECT  TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time  FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `)  GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
-	o := orm.NewOrm()
-	o.Using("edb")
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-// TargetItemListResp 指标数据结构体
-type TargetItemListResp struct {
-	List          []*EdbInfoItem
-	FrequencyList []string
-}
-
-// BatchDataDeleteReq 批量删除某日的指标数据请求结构体
-type BatchDataDeleteReq struct {
-	CreateDate    string   `description:"创建日期"`
-	TradeCodeList []string `description:"指标唯一编码列表"`
-}
-
-// BatchDeleteEdbDataByDate 批量删除某日的指标数据
-func BatchDeleteEdbDataByDate(tradeCodes, dt string, opUserId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	var list []*Edbdata
-	sql := ` select * FROM edbdata WHERE TRADE_CODE in  (` + tradeCodes + `) AND DT = ? `
-	_, err = o.Raw(sql, dt).QueryRows(&list)
-	if err != nil {
-		return
-	}
-	deleteRecordList := make([]*EdbdataDeleteRecord, 0)
-	for _, edbDataInfo := range list {
-		deleteRecord := &EdbdataDeleteRecord{
-			TradeCode:  edbDataInfo.TradeCode,
-			Dt:         edbDataInfo.Dt,
-			Close:      edbDataInfo.Close,
-			ModifyTime: time.Now(),
-			CreateTime: time.Now(),
-			SysUserId:  opUserId,
-		}
-		deleteRecordList = append(deleteRecordList, deleteRecord)
-	}
-	if len(deleteRecordList) > 0 {
-		_, tmpErr := o.InsertMulti(len(deleteRecordList), deleteRecordList)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-	}
-	sql = ` DELETE FROM edbdata WHERE TRADE_CODE in  (` + tradeCodes + `) AND DT = ? `
-	_, err = o.Raw(sql, dt).Exec()
-	return
-}
-
-// BatchDeleteEdbData 批量删除指标数据
-func BatchDeleteEdbData(tradeCode string, opUserId int) (err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	var list []*Edbdata
-	sql := ` select * FROM edbdata WHERE TRADE_CODE =  ? `
-	_, err = o.Raw(sql, tradeCode).QueryRows(&list)
-	if err != nil {
-		return
-	}
-	deleteRecordList := make([]*EdbdataDeleteRecord, 0)
-	for _, edbDataInfo := range list {
-		deleteRecord := &EdbdataDeleteRecord{
-			TradeCode:  edbDataInfo.TradeCode,
-			Dt:         edbDataInfo.Dt,
-			Close:      edbDataInfo.Close,
-			ModifyTime: time.Now(),
-			CreateTime: time.Now(),
-			SysUserId:  opUserId,
-		}
-		deleteRecordList = append(deleteRecordList, deleteRecord)
-	}
-	_, err = o.InsertMulti(len(deleteRecordList), deleteRecordList)
-	if err != nil {
-		return
-	}
-	sql = ` DELETE FROM edbdata WHERE TRADE_CODE  = ? `
-	_, err = o.Raw(sql, tradeCode).Exec()
-	return
-}
-
-// GetEdbInfoCountByClassifyId 根据指标分类id获取当前分类下的指标数量
-func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a 
-             INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id=? group by a.TRADE_CODE) d `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-// EdbInfoGroupCount 指标分类id获取当前分类下的指标数量
-type EdbInfoGroupCount struct {
-	Count      int
-	ClassifyId int
-}
-
-// GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
-func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
-	o := orm.NewOrm()
-	o.Using("edb")
-	sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a 
-             INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' and a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d 
-						 GROUP BY classify_id `
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}

+ 30 - 0
services/alarm_msg/alarm_msg.go

@@ -0,0 +1,30 @@
+package alarm_msg
+
+import (
+	"encoding/json"
+	"github.com/rdlucklib/rdluck_tools/http"
+	"hongze/hongze_chart_lib/utils"
+)
+
+var (
+	AlarmMsgUrl = "http://127.0.0.1:8606/api/alarm/send"
+)
+
+// SendAlarmMsg
+//projectName-项目名称
+//runMode-运行模式
+//msgBody-消息内容
+//level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
+func SendAlarmMsg(msgBody string, level int) {
+	params := make(map[string]interface{})
+	params["ProjectName"] = utils.APPNAME
+	params["RunMode"] = utils.RunMode
+	params["MsgBody"] = msgBody
+	params["Level"] = level
+	param, err := json.Marshal(params)
+	if err != nil {
+		utils.FileLog.Info("SendAlarmMsg json.Marshal Err:" + err.Error())
+		return
+	}
+	http.Post(AlarmMsgUrl, string(param))
+}

+ 152 - 0
services/data/base_edb_lib.go

@@ -0,0 +1,152 @@
+package data
+
+import (
+	"encoding/json"
+	"fmt"
+	"hongze/hongze_chart_lib/models"
+	"hongze/hongze_chart_lib/utils"
+	"io/ioutil"
+	"net/http"
+	"strings"
+)
+
+//新增指标数据
+func AddEdbData(source int, edbCode string) (resp *models.BaseResponse, err error) {
+	param := make(map[string]interface{})
+	param["EdbCode"] = edbCode
+	urlStr := ``
+	switch source {
+	case utils.DATA_SOURCE_THS:
+		urlStr = "/ths/add"
+	case utils.DATA_SOURCE_WIND:
+		urlStr = "/wind/add"
+	case utils.DATA_SOURCE_PB:
+		urlStr = "/pb/add"
+	case utils.DATA_SOURCE_MANUAL:
+		urlStr = "/manual/add"
+	case utils.DATA_SOURCE_LZ:
+		urlStr = "/lz/add"
+	case utils.DATA_SOURCE_YS:
+		urlStr = "/smm/add"
+	case utils.DATA_SOURCE_GL:
+		urlStr = "/mysteel/add"
+	case utils.DATA_SOURCE_ZZ:
+		urlStr = "/zz/add"
+	case utils.DATA_SOURCE_DL:
+		urlStr = "/dl/add"
+	case utils.DATA_SOURCE_SH:
+		urlStr = "/sh/add"
+	case utils.DATA_SOURCE_CFFEX:
+		urlStr = "/cffex/add"
+	case utils.DATA_SOURCE_SHFE:
+		urlStr = "/shfe/add"
+	case utils.DATA_SOURCE_GIE:
+		urlStr = "/gie/add"
+	case utils.DATA_SOURCE_LT:
+		urlStr = "/lt/add"
+	case utils.DATA_SOURCE_COAL:
+		urlStr = "/coal/add"
+	default:
+	}
+	if urlStr == "" {
+		err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
+		return
+	}
+	resp, err = postRefreshEdbData(param, urlStr)
+	return
+}
+
+// RefreshEdbData 刷新指标数据
+func RefreshEdbData(edbInfoId, source int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
+	param := make(map[string]interface{})
+	param["EdbCode"] = edbCode
+	param["EdbInfoId"] = edbInfoId
+	param["StartDate"] = startDate
+	urlStr := ``
+	switch source {
+	case utils.DATA_SOURCE_THS:
+		urlStr = "/ths/refresh"
+	case utils.DATA_SOURCE_WIND:
+		urlStr = "/wind/refresh"
+	case utils.DATA_SOURCE_PB:
+		urlStr = "/pb/refresh"
+	case utils.DATA_SOURCE_MANUAL:
+		urlStr = "/manual/refresh"
+	case utils.DATA_SOURCE_LZ:
+		urlStr = "/lz/refresh"
+	case utils.DATA_SOURCE_YS:
+		urlStr = "/smm/refresh"
+	case utils.DATA_SOURCE_GL:
+		urlStr = "/mysteel/refresh"
+	case utils.DATA_SOURCE_ZZ:
+		urlStr = "/zz/refresh"
+	case utils.DATA_SOURCE_DL:
+		urlStr = "/dl/refresh"
+	case utils.DATA_SOURCE_SH:
+		urlStr = "/sh/refresh"
+	case utils.DATA_SOURCE_CFFEX:
+		urlStr = "/cffex/refresh"
+	case utils.DATA_SOURCE_SHFE:
+		urlStr = "/shfe/refresh"
+	case utils.DATA_SOURCE_GIE:
+		urlStr = "/gie/refresh"
+	case utils.DATA_SOURCE_LT:
+		urlStr = "/lt/refresh"
+	case utils.DATA_SOURCE_COAL:
+		urlStr = "/coal/refresh"
+	}
+	if urlStr == "" {
+		err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
+		return
+	}
+	resp, err = postRefreshEdbData(param, urlStr)
+	return
+}
+
+// RefreshEdbCalculateData 刷新计算指标数据请求
+func RefreshEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
+	param := make(map[string]interface{})
+	param["EdbCode"] = edbCode
+	param["EdbInfoId"] = edbInfoId
+	param["StartDate"] = startDate
+	resp, err = postRefreshEdbData(param, "/calculate/refresh")
+	return
+}
+
+// postRefreshEdbData 刷新指标数据
+func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
+	postUrl := utils.EDB_LIB_URL + urlStr
+	postData, err := json.Marshal(param)
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+	err = json.Unmarshal(result, &resp)
+	if err != nil {
+		return
+	}
+	return resp, nil
+}
+
+func HttpPost(url, postData string, params ...string) ([]byte, error) {
+	body := ioutil.NopCloser(strings.NewReader(postData))
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", url, body)
+	if err != nil {
+		return nil, err
+	}
+	contentType := "application/x-www-form-urlencoded;charset=utf-8"
+	if len(params) > 0 && params[0] != "" {
+		contentType = params[0]
+	}
+	req.Header.Set("Content-Type", contentType)
+	req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
+	resp, err := client.Do(req)
+	defer resp.Body.Close()
+	b, err := ioutil.ReadAll(resp.Body)
+	fmt.Println("HttpPost:" + string(b))
+	return b, err
+}

文件差异内容过多而无法显示
+ 0 - 69
services/data/base_from_smm.go


+ 0 - 86
services/data/chart_classify.go

@@ -1,86 +0,0 @@
-package data
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/models/data_manage"
-)
-
-func ChartClassifyListMakeTree(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) {
-	childs, _ := chartClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
-	allChartInfo, _ := GetChartClassifyChartInfo()
-	if len(childs) > 0 {
-		node.Children = append(node.Children, childs[0:]...) //添加子节点
-		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
-			_, has := chartClassifyHaveChild(allNode, v)
-			if has {
-				ChartClassifyListMakeTree(allNode, v) //递归添加节点
-			} else {
-				fmt.Println(v.ChartClassifyId)
-
-				edbInfoList := allChartInfo[v.ChartClassifyId]
-
-				v.Children = edbInfoList
-				if v.Children == nil {
-					childrenArr := make([]*data_manage.ChartClassifyItems, 0)
-					v.Children = childrenArr
-				}
-			}
-		}
-	} else {
-		childrenArr := make([]*data_manage.ChartClassifyItems, 0)
-		node.Children = childrenArr
-	}
-}
-
-func chartClassifyHaveChild(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) (childs []*data_manage.ChartClassifyItems, yes bool) {
-	for _, v := range allNode {
-		if v.ParentId == node.ChartClassifyId {
-			childs = append(childs, v)
-		}
-	}
-	if len(childs) > 0 {
-		yes = true
-	}
-	return
-}
-
-func GetChartClassifyChartInfo() (result map[int][]*data_manage.ChartClassifyItems, err error) {
-	cMap := make(map[int][]*data_manage.ChartClassifyItems)
-	items, err := data_manage.GetChartInfoAll()
-	if err != nil {
-		return
-	}
-	for _, v := range items {
-		childrenArr := make([]*data_manage.ChartClassifyItems, 0)
-		v.Children = childrenArr
-		if items, ok := cMap[v.ChartClassifyId]; ok {
-			items = append(items, v)
-			cMap[v.ChartClassifyId] = items
-		} else {
-			infoList := make([]*data_manage.ChartClassifyItems, 0)
-			infoList = append(infoList, v)
-			cMap[v.ChartClassifyId] = infoList
-		}
-	}
-	result = cMap
-	return
-}
-
-func ChartClassifyItemsMakeTree(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) {
-	childs, _ := chartClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
-	if len(childs) > 0 {
-		node.Children = append(node.Children, childs[0:]...) //添加子节点
-		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
-			_, has := chartClassifyHaveChild(allNode, v)
-			if has {
-				ChartClassifyItemsMakeTree(allNode, v) //递归添加节点
-			} else {
-				childrenArr := make([]*data_manage.ChartClassifyItems, 0)
-				v.Children = childrenArr
-			}
-		}
-	} else {
-		childrenArr := make([]*data_manage.ChartClassifyItems, 0)
-		node.Children = childrenArr
-	}
-}

+ 36 - 511
services/data/chart_info.go

@@ -1,15 +1,16 @@
 package data
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_chart_lib/models/data_manage"
 	"hongze/hongze_chart_lib/utils"
 	"sort"
-	"strconv"
 	"time"
 )
 
-func ChartInfoRefresh(chartInfoId int) (err error) {
+// ChartInfoRefreshV1 图表刷新
+func ChartInfoRefreshV1(chartInfoId int) (err error) {
 	var errmsg string
 	defer func() {
 		if err != nil {
@@ -51,356 +52,43 @@ func ChartInfoRefresh(chartInfoId int) (err error) {
 		edbInfoId := bv.EdbInfoId
 		edbCode := bv.EdbCode
 		startDate = bv.StartDate
+		frequency := bv.Frequency
+		if bv.StartDate == "0000-00-00" {
+			continue
+		}
 		sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
 		if err != nil {
 			return err
 		}
-		startDate = sTime.Format(utils.FormatDate)
-
-		if source == utils.DATA_SOURCE_THS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = RefreshEdbDataByThs(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByThs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_WIND {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = RefreshEdbDataByWind(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByWind Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_PB {
-			startDate := sTime.Format(utils.FormatDateUnSpace)
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
-			err = RefreshEdbDataByPb(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByPb Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_MANUAL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByManual(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByManual Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_LZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByLz(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByLz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_YS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByYs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_GL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByGl(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByGl Err:" + err.Error()
-			}
-		}else if source == utils.DATA_SOURCE_LT {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLt(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLT Err:" + err.Error()
-			}
-		}
 
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil {
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-	}
-
-	for _, v := range calculateArr {
-		edbInfo := calculateMap[v]
-		if edbInfo == nil {
-			return err
-		}
-		edbInfoId := edbInfo.EdbInfoId
-		source := edbInfo.Source
-		edbCode := edbInfo.EdbCode
+		var limitDay int
+		startDate := ""
+		switch frequency {
+		case "日度":
+			limitDay = utils.DATA_REFRESH
+		case "周度":
+			limitDay = utils.DATA_REFRESH * 7
+		case "月度":
+			limitDay = utils.DATA_REFRESH * 30
+		case "季度":
+			limitDay = utils.DATA_REFRESH * 90
+		case "年度":
+			limitDay = utils.DATA_REFRESH * 365
+		default:
+			limitDay = utils.DATA_REFRESH
+		}
+		startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
 
 		fmt.Println("source:", source)
-		fmt.Println("edbInfoId:", edbInfoId)
-
-		if source == utils.DATA_SOURCE_CALCULATE { //指标运算
-			startDate = edbInfo.StartDate
-			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-			if err != nil {
-				return err
-			}
-			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			fmt.Println("start RefreshCalculate")
-			endDate := ""
-			err = RefreshCalculate(edbInfoList, int(edbInfoId), edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			year := time.Now().Year()
-			startDate = strconv.Itoa(year) + "-01" + "-01"
-			endDate := ""
-			err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate := "" // time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate := "" //time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate := "" //time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateHbz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate := "" //time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateHcz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateBpDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate := "" //time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateBp Err:" + err.Error()
-				return err
-			}
-		}
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
+		respItem, err := RefreshEdbData(edbInfoId, source, edbCode, startDate)
 		if err != nil {
+			errmsg = errors.New("RefreshEdbData Err:" + err.Error()).Error()
 			return err
 		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	return err
-}
-
-func ChartInfoRefreshV1(chartInfoId int) (err error) {
-	var errmsg string
-	defer func() {
-		if err != nil {
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ChartInfoRefresh:"+errmsg, utils.EmailSendToUsers)
-			fmt.Println("ChartInfoRefresh Err:" + errmsg)
-		}
-	}()
-	baseEdbInfoArr, calculateInfoArr, err := data_manage.GetChartInfoRefreshData(chartInfoId)
-	if err != nil {
-		errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
-		return
-	}
-	var startDate string
-
-	newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-	baseMap := make(map[int]*data_manage.EdbInfo)
-	for _, bv := range baseEdbInfoArr {
-		if _, ok := baseMap[bv.EdbInfoId]; !ok {
-			newBaseEdbInfoArr = append(newBaseEdbInfoArr, bv)
-		}
-		baseMap[bv.EdbInfoId] = bv
-	}
-
-	fmt.Println("calculateInfoArr:", len(calculateInfoArr))
-
-	newCalculateInfoArr := make([]*data_manage.EdbInfo, 0)
-	calculateMap := make(map[int]*data_manage.EdbInfo)
-	var calculateArr []int
-	for _, bv := range calculateInfoArr {
-		if _, ok := calculateMap[bv.EdbInfoId]; !ok {
-			newCalculateInfoArr = append(newCalculateInfoArr, bv)
-			calculateArr = append(calculateArr, bv.EdbInfoId)
-		}
-		calculateMap[bv.EdbInfoId] = bv
-	}
-	sort.Ints(calculateArr)
-	for _, bv := range newBaseEdbInfoArr {
-		source := bv.Source
-		edbInfoId := bv.EdbInfoId
-		edbCode := bv.EdbCode
-		startDate = bv.StartDate
-		sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
-		if err != nil {
+		if respItem.Ret != 200 {
+			errmsg = errors.New(respItem.ErrMsg + ";EdbCode:" + edbCode).Error()
 			return err
 		}
-		startDate = sTime.Format(utils.FormatDate)
-
-		if source == utils.DATA_SOURCE_THS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = RefreshEdbDataByThs(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByThs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_WIND {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = RefreshEdbDataByWind(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByWind Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_PB {
-			startDate := sTime.Format(utils.FormatDateUnSpace)
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
-			err = RefreshEdbDataByPb(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByPb Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_MANUAL {
-			err = data_manage.RefreshAllEdbDataByManual(edbInfoId,bv.Source, edbCode)
-			if err != nil {
-				errmsg = "RefreshEdbDataByManual Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_LZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByLz(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByLz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_YS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByYs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_GL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByGl(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByGl Err:" + err.Error()
-			}
-		}else if source == utils.DATA_SOURCE_LT {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLt(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLT Err:" + err.Error()
-			}
-		}
 
 		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
 		if err != nil {
@@ -414,16 +102,14 @@ func ChartInfoRefreshV1(chartInfoId int) (err error) {
 		}
 	}
 
-	endDate := "" //计算指标不限制日期
 	//刷新相关计算指标
 	for _, v := range calculateArr {
 		edbInfo := calculateMap[v]
 		if edbInfo == nil {
 			return err
 		}
-		edbInfoId := edbInfo.EdbInfoId
+		startDate = edbInfo.StartDate
 		source := edbInfo.Source
-		edbCode := edbInfo.EdbCode
 
 		if source == utils.DATA_SOURCE_CALCULATE {
 			startDate = edbInfo.StartDate
@@ -432,179 +118,18 @@ func ChartInfoRefreshV1(chartInfoId int) (err error) {
 				return err
 			}
 			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			err = data_manage.RefreshAllCalculate(edbInfoList, int(edbInfoId), source, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateLjzzy(edbInfoId, source, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateTbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateTcz(edbInfoId, source, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			startDate = edbInfo.StartDate
-			err = data_manage.RefreshAllCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode, startDate)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshAllCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-			if err != nil {
-				errmsg = "RefreshAllCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshAllCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-			if err != nil {
-				errmsg = "RefreshAllCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateBp(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateBp Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接数据
-			err = data_manage.RefreshAllCalculateZjpj(edbInfo)
-			if err != nil {
-				errmsg = "RefreshAllCalculateZjpj Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接数据
-			err = data_manage.RefreshAllCalculateLjztbpj(edbInfo)
-			if err != nil {
-				errmsg = "RefreshAllCalculateLjztbpj Err:" + err.Error()
-				return err
-			}
 		}
 
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
+		result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
 		if err != nil {
+			fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
+			errmsg = "RefreshEdbCalculateData Err:" + err.Error()
 			return err
 		}
-
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
+		if result.Ret != 200 {
+			fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
+			errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
+			return fmt.Errorf("刷新失败" + errmsg)
 		}
 		fmt.Println("end calculateArr:", v, time.Now())
 	}

+ 0 - 119
services/data/edb_classify.go

@@ -1,119 +0,0 @@
-package data
-
-import (
-	"fmt"
-	"hongze/hongze_chart_lib/models"
-	"hongze/hongze_chart_lib/models/data_manage"
-)
-
-func EdbClassifyListMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
-	childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
-	allEdbInfo, _ := GetEdbClassifyEdbInfo()
-	if len(childs) > 0 {
-		node.Children = append(node.Children, childs[0:]...) //添加子节点
-		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
-			_, has := edbClassifyHaveChild(allNode, v)
-			if has {
-				EdbClassifyListMakeTree(allNode, v) //递归添加节点
-			} else {
-				edbInfoList := allEdbInfo[v.ClassifyId]
-				v.Children = edbInfoList
-				if v.Children == nil {
-					childrenArr := make([]*data_manage.EdbClassifyItems, 0)
-					v.Children = childrenArr
-				}
-			}
-		}
-	} else {
-		childrenArr := make([]*data_manage.EdbClassifyItems, 0)
-		node.Children = childrenArr
-	}
-}
-
-func edbClassifyHaveChild(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) (childs []*data_manage.EdbClassifyItems, yes bool) {
-	for _, v := range allNode {
-		if v.ParentId == node.ClassifyId {
-			childs = append(childs, v)
-		}
-	}
-
-	if len(childs) > 0 {
-		yes = true
-	}
-	return
-}
-
-func GetEdbClassifyEdbInfo() (result map[int][]*data_manage.EdbClassifyItems, err error) {
-	cMap := make(map[int][]*data_manage.EdbClassifyItems)
-	items, err := data_manage.GetEdbInfoAll()
-	if err != nil {
-		return
-	}
-	for _, v := range items {
-		childrenArr := make([]*data_manage.EdbClassifyItems, 0)
-		v.Children = childrenArr
-		if items, ok := cMap[v.ClassifyId]; ok {
-			items = append(items, v)
-			cMap[v.ClassifyId] = items
-		} else {
-			infoList := make([]*data_manage.EdbClassifyItems, 0)
-			infoList = append(infoList, v)
-			cMap[v.ClassifyId] = infoList
-		}
-	}
-	result = cMap
-	return
-}
-
-func EdbClassifyItemsMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
-	childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
-	if len(childs) > 0 {
-		node.Children = append(node.Children, childs[0:]...) //添加子节点
-		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
-			_, has := edbClassifyHaveChild(allNode, v)
-			if has {
-				EdbClassifyItemsMakeTree(allNode, v) //递归添加节点
-			} else {
-				childrenArr := make([]*data_manage.EdbClassifyItems, 0)
-				v.Children = childrenArr
-			}
-		}
-	} else {
-		childrenArr := make([]*data_manage.EdbClassifyItems, 0)
-		node.Children = childrenArr
-	}
-}
-
-// GetEdbClassifyListByAdminId 根据账户类型获取分类id集合
-func GetEdbClassifyListByAdminId(adminId int64) (classifyIdList []string, err error) {
-	list, err := models.GetEdbdataClassify(adminId)
-	if err != nil {
-		return
-	}
-	for _, parent := range list {
-		if parent.Child != nil {
-			for _, classify := range parent.Child {
-				classifyIdList = append(classifyIdList, fmt.Sprint(classify.ClassifyId))
-			}
-		}
-	}
-	return
-}
-
-// GetEdbClassifyNameListByAdminId 根据账户类型获取分类名称集合
-func GetEdbClassifyNameListByAdminId(adminId int64) (classifyNameList []string, edbDataClassifyMap map[string]*models.EdbdataClassify, err error) {
-	list, err := models.GetEdbdataClassify(adminId)
-	edbDataClassifyMap = make(map[string]*models.EdbdataClassify)
-	if err != nil {
-		return
-	}
-	for _, parent := range list {
-		if parent.Child != nil {
-			for _, classify := range parent.Child {
-				classifyNameList = append(classifyNameList, classify.ClassifyName)
-				edbDataClassifyMap[classify.ClassifyName] = classify
-			}
-		}
-	}
-	return
-}

+ 0 - 9
services/data/edb_data.go

@@ -1,9 +0,0 @@
-package data
-
-// EdbDataEdit 指标数据修改
-type EdbDataEdit struct {
-	OldCreateDate string `description:"旧的录入日期"`
-	CreateDate    string `description:"新的录入日期"`
-	TradeCode     string `description:"指标唯一编码"`
-	Close         string `description:"录入值"`
-}

+ 0 - 169
services/data/edb_data_pb.go

@@ -1,169 +0,0 @@
-package data
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"net/url"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"strings"
-	"time"
-)
-
-type EdbDataFromPb struct {
-	Date   map[string]int64   `json:"date"`
-	Ticker map[string]string  `json:"ticker"`
-	Field  map[string]string  `json:"field"`
-	Value  map[string]float64 `json:"value"`
-}
-
-func GetEdbDataByPb(edbCode, startDate, endDate string) (searchItem *data_manage.EdbInfoSearch, err error) {
-	defer func() {
-		if err != nil {
-			utils.FileLog.Info("GetEdbDataByPb Err:%s", err.Error())
-		}
-	}()
-	edbCode = url.QueryEscape(edbCode)
-	bpUrl := utils.Hz_Data_PB_Url + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
-	bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("bpUrl:%s", bpUrl)
-	body, err := http.Get(bpUrl)
-	if err != nil {
-		utils.FileLog.Info("GetEdbDataByPb Err:%s", err.Error())
-		return
-	}
-	utils.FileLog.Info("GetEdbDataByPb result:%s", string(body))
-	item := new(EdbDataFromPb)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:%s", err.Error())
-		return
-	}
-	edbCode, _ = url.QueryUnescape(edbCode)
-	searchItem = new(data_manage.EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	if len(item.Date) > 0 {
-		var isAdd bool
-		dateMap := item.Date
-		addSql := ` INSERT INTO edb_data_pb(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,ticker,field,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		for k, v := range dateMap {
-			timeStr := fmt.Sprintf("%d", v)
-			v = v / 1000
-			t := time.Unix(v, 0)
-			dateTime := t.Format(utils.FormatDate)
-
-			val := item.Value[k]
-			field := item.Field[k]
-			ticker := item.Ticker[k]
-
-			if field == "PX_LAST" {
-				addSql += "("
-				addSql += "0," + "'" + edbCode + "'" + "," + "'" + dateTime + "'" + "," + utils.SubFloatToString(val, 20) + "," + "'" + nowStr + "'" +
-					"," + "'" + nowStr + "'" + "," + "0" + "," + "'" + ticker + "'" + "," + "'" + field + "'" + "," + "'" + timeStr + "'"
-				addSql += "),"
-				isAdd = true
-			}
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			err = data_manage.AddEdbDataPbBySql(addSql)
-			if err != nil {
-				utils.FileLogData.Info("GetEdbDataByPb AddEdbDataPbBySql Err:%s", err.Error())
-				return searchItem, err
-			}
-		}
-
-		size := utils.EDB_DATA_LIMIT
-		dataList, err := data_manage.GetEdbDataPbByCode(edbCode, size)
-		if err != nil {
-			fmt.Println("GetEdbDataWindByCode Err", err.Error())
-			return searchItem, err
-		}
-		minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
-		if err != nil {
-			return searchItem, err
-		}
-		searchItem.DataList = dataList
-		searchItem.StartDate = minDate
-		searchItem.EndDate = maxDate
-	}
-
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*data_manage.EdbInfoSearchData, 0)
-	}
-
-	return
-}
-
-func RefreshEdbDataByPb(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	refreshEdbCode := edbCode
-	edbCode = url.QueryEscape(edbCode)
-	bpUrl := utils.Hz_Data_PB_Url + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
-	bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("bpUrl+" + bpUrl)
-	body, err := http.Get(bpUrl)
-	fmt.Println("RefreshEdbDataByPb body:")
-	fmt.Println(string(body))
-	utils.FileLog.Info("RefreshEdbDataByPb:" + string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromPb)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	if len(item.Date) > 0 {
-		dateMap := item.Date
-		pbList := make([]*data_manage.EdbDataPb, 0)
-		for k, v := range dateMap {
-			timestamp := v
-			v = v / 1000
-			t := time.Unix(v, 0)
-			dateTime := t.Format(utils.FormatDate)
-
-			val := item.Value[k]
-			field := item.Field[k]
-			ticker := item.Ticker[k]
-			if field == "PX_LAST" {
-				//判断数据是否已经存在
-				count, err := data_manage.GetEdbDataPbByCodeAndDate(refreshEdbCode, dateTime)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
-				}
-				fmt.Println("field:", field)
-				if count <= 0 {
-					item := new(data_manage.EdbDataPb)
-					item.EdbCode, _ = url.QueryUnescape(edbCode)
-					item.EdbInfoId = edbInfoId
-					item.CreateTime = time.Now()
-					item.ModifyTime = time.Now()
-					item.DataTime = dateTime
-					item.Value = val
-					item.Status = 1
-					item.Field = field
-					item.Ticker = ticker
-					item.DataTimestamp = timestamp
-					pbList = append(pbList, item)
-				} else {
-					err = data_manage.ModifyEdbDataPb(edbInfoId, dateTime, val)
-					if err != nil {
-						return err
-					}
-				}
-			}
-		}
-
-		if len(pbList) > 0 {
-			err = data_manage.AddEdbDataPb(pbList)
-			if err != nil {
-				fmt.Println("AddEdbDataPb Err", err.Error())
-				return
-			}
-		}
-	}
-	return
-}

+ 0 - 166
services/data/edb_data_ths.go

@@ -1,166 +0,0 @@
-package data
-
-import (
-	"encoding/json"
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataFromThs struct {
-	DataVol   int64       `json:"dataVol"`
-	Errmsg    string      `json:"errmsg"`
-	Errorcode int64       `json:"errorcode"`
-	Perf      interface{} `json:"perf"`
-	Tables    []struct {
-		ID    []string  `json:"id"`
-		Time  []string  `json:"time"`
-		Value []float64 `json:"value"`
-	} `json:"tables"`
-}
-
-func GetEdbDataByThs(edbCode, startDate, endDate string) (searchItem *data_manage.EdbInfoSearch, err error) {
-	thsUrl := utils.Hz_Server_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLogData.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	utils.FileLogData.Info("ths result:%s", string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromThs)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	if item.Errorcode != 0 {
-		err = errors.New(string(body))
-		return
-	}
-	searchItem = new(data_manage.EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-	if len(item.Tables) > 0 {
-		table := item.Tables[0]
-		dataLen := len(table.Time)
-
-		var isAdd bool
-		addSql := ` INSERT INTO edb_data_ths(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		dataList := make([]*data_manage.EdbInfoSearchData, 0)
-		for i := 0; i < dataLen; i++ {
-			eDate := table.Time[i]
-			sValue := table.Value[i]
-			dataTime, err := time.Parse(utils.FormatDate, eDate)
-			if err != nil {
-				return nil, err
-			}
-			timestamp := dataTime.UnixNano() / 1e6
-			timeStr := fmt.Sprintf("%d", timestamp)
-			addSql += "("
-			addSql += "0," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + utils.SubFloatToString(sValue, 20) + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "0" + "," + "'" + timeStr + "'"
-			addSql += "),"
-			isAdd = true
-		}
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			err = data_manage.AddEdbDataThsBySql(addSql)
-			if err != nil {
-				utils.FileLogData.Info("AddEdbDataThsBySql Err:%s", err.Error())
-				return
-			}
-		}
-
-		size := utils.EDB_DATA_LIMIT
-		dataList, err := data_manage.GetEdbDataThsByCode(edbCode, size)
-		if err != nil {
-			utils.FileLogData.Info("GetEdbDataThsByCode Err:%s", err.Error())
-			return searchItem, err
-		}
-		minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
-		if err != nil {
-			return searchItem, err
-		}
-		searchItem.DataList = dataList
-		searchItem.StartDate = minDate
-		searchItem.EndDate = maxDate
-	}
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*data_manage.EdbInfoSearchData, 0)
-	}
-	return
-}
-
-func RefreshEdbDataByThs(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	thsUrl := utils.Hz_Server_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	fmt.Println("GetEdbDataByThs body:")
-	fmt.Println(string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromThs)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	if item.Errorcode != 0 {
-		err = errors.New(string(body))
-		return
-	}
-	if len(item.Tables) > 0 {
-		table := item.Tables[0]
-		dataLen := len(table.Time)
-		addSql := ` INSERT INTO edb_data_ths(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-		nowStr := time.Now().Format(utils.FormatDateTime)
-		var isAdd bool
-		for i := 0; i < dataLen; i++ {
-			eDate := table.Time[i]
-			sValue := table.Value[i]
-
-			count, err := data_manage.GetEdbDataThsByCodeAndDate(edbCode, eDate)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 {
-				dataTime, err := time.Parse(utils.FormatDate, eDate)
-				if err != nil {
-
-				}
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-
-				addSql += "("
-				addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + utils.SubFloatToString(sValue, 30) + "," + "'" + nowStr + "'" +
-					"," + "'" + nowStr + "'" + "," + "1"
-				addSql += "," + "'" + timeStr + "'"
-				addSql += "),"
-				isAdd = true
-			} else {
-				err = data_manage.ModifyEdbDataThs(int64(edbInfoId), eDate, sValue)
-				if err != nil {
-					return err
-				}
-			}
-		}
-
-		if isAdd {
-			addSql = strings.TrimRight(addSql, ",")
-			err = data_manage.AddEdbDataThsBySql(addSql)
-			if err != nil {
-				fmt.Println("AddEdbDataThs Err", err.Error())
-				return
-			}
-		}
-	}
-	return
-}

+ 0 - 155
services/data/edb_data_wind.go

@@ -1,155 +0,0 @@
-package data
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"github.com/rdlucklib/rdluck_tools/http"
-	"strconv"
-	"strings"
-	"time"
-)
-
-type EdbDataFromWind struct {
-	Close  map[string]float64 `json:"CLOSE"`
-	Dt     map[string]int64   `json:"DT"`
-	ErrMsg string
-}
-
-//万得
-func GetEdbDataByWind(edbCode, startDate, endDate string) (searchItem *data_manage.EdbInfoSearch, err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println("GetEdbDataByWind Err:" + err.Error())
-		}
-	}()
-
-	thsUrl := utils.Hz_Data_Url + `edbInfo/wind?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	fmt.Println("GetEdbDataByThs body:")
-	fmt.Println(string(body))
-	utils.FileLog.Info("wind %s", string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromWind)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	var isAdd bool
-	addSql := ` INSERT INTO edb_data_wind(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	for k, v := range item.Dt {
-		timeStr := fmt.Sprintf("%d", v)
-		v = v / 1000
-		t := time.Unix(v, 0)
-		dateTime := t.Format(utils.FormatDate)
-		val := item.Close[k]
-
-		addSql += "("
-		addSql += "0," + "'" + edbCode + "'" + "," + "'" + dateTime + "'" + "," + utils.SubFloatToString(val, 20) + "," + "'" + nowStr + "'" +
-			"," + "'" + nowStr + "'" + "," + "0" + "," + "'" + timeStr + "'"
-		addSql += "),"
-		isAdd = true
-	}
-	searchItem = new(data_manage.EdbInfoSearch)
-	searchItem.EdbCode = edbCode
-
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		err = data_manage.AddEdbDataWindBySql(addSql)
-		if err != nil {
-			utils.FileLogData.Info("GetEdbDataByPb AddEdbDataPbBySql Err:%s", err.Error())
-			return searchItem, err
-		}
-	}
-	size := utils.EDB_DATA_LIMIT
-	dataList, err := data_manage.GetEdbDataWindByCode(edbCode, size)
-	if err != nil {
-		fmt.Println("GetEdbDataWindByCode Err", err.Error())
-		return searchItem, err
-	}
-	minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
-	if err != nil {
-		fmt.Println("GetEdbDataWindByCode Err", err.Error())
-		return searchItem, err
-	}
-	searchItem.DataList = dataList
-	searchItem.StartDate = minDate
-	searchItem.EndDate = maxDate
-	if searchItem.DataList == nil {
-		searchItem.DataList = make([]*data_manage.EdbInfoSearchData, 0)
-	}
-	return
-}
-
-func RefreshEdbDataByWind(edbInfoId int, edbCode, startDate, endDate string) (err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println("GetEdbDataByWind Err:" + err.Error())
-		}
-	}()
-
-	fmt.Println("startDate,endDate:",startDate,endDate)
-
-	thsUrl := utils.Hz_Data_Url + `edbInfo/wind?EdbCode=%s&StartDate=%s&EndDate=%s`
-	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
-	utils.FileLog.Info("thsUrl:%s", thsUrl)
-	body, err := http.Get(thsUrl)
-	fmt.Println("GetEdbDataByThs body:")
-	fmt.Println(string(body))
-	utils.FileLog.Info("wind result:"+string(body))
-
-	if err != nil {
-		return
-	}
-	item := new(EdbDataFromWind)
-	err = json.Unmarshal(body, &item)
-	if err != nil {
-		return
-	}
-	addSql := ` INSERT INTO edb_data_wind(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	var isAdd bool
-	for k, v := range item.Dt {
-		timeStr := fmt.Sprintf("%d", v)
-
-		v = v / 1000
-		t := time.Unix(v, 0)
-		dateTime := t.Format(utils.FormatDate)
-		val := item.Close[k]
-
-		count, err := data_manage.GetEdbDataWindByCodeAndDate(edbCode, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return err
-		}
-		if count <= 0 {
-			isAdd = true
-			fmt.Println(dateTime)
-			addSql += "("
-			addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + dateTime + "'" + "," + utils.SubFloatToString(val, 30) + "," + "'" + nowStr + "'" +
-				"," + "'" + nowStr + "'" + "," + "1"
-			addSql += "," + "'" + timeStr + "'"
-			addSql += "),"
-		} else {
-			err = data_manage.ModifyEdbDataWind(int64(edbInfoId), dateTime, val)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		err = data_manage.AddEdbDataWindBySql(addSql)
-		if err != nil {
-			fmt.Println("AddEdbDataWind Err", err.Error())
-			return
-		}
-	}
-	return
-}

+ 0 - 1639
services/data/edb_info.go

@@ -1,1639 +0,0 @@
-package data
-
-import (
-	"errors"
-	"fmt"
-	"hongze/hongze_chart_lib/models"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"sort"
-	"strconv"
-	"time"
-)
-
-//刷新计算指标
-func EdbInfoRefreshFromCalculate(edbInfoId, source int) (err error) {
-	var errmsg string
-	defer func() {
-		fmt.Println("errmsg:" + errmsg)
-		if err != nil {
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromCalculate:"+errmsg, utils.EmailSendToUsers)
-		}
-	}()
-	baseEdbInfoArr, calculateInfoArr, err := data_manage.GetRefreshEdbInfoFromCalculate(edbInfoId, source)
-	if err != nil {
-		errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
-		return
-	}
-	calculateItem, _ := data_manage.GetEdbInfoById(edbInfoId)
-	calculateInfoArr = append(calculateInfoArr, calculateItem)
-	var calculateArr []int
-	calculateMap := make(map[int]*data_manage.EdbInfo)
-	for _, v := range calculateInfoArr {
-		if _, ok := calculateMap[v.EdbInfoId]; !ok {
-			calculateArr = append(calculateArr, v.EdbInfoId)
-		}
-		calculateMap[v.EdbInfoId] = v
-	}
-	sort.Ints(calculateArr)
-
-	var startDate string
-	endDate := time.Now().Format(utils.FormatDate)
-	for _, bv := range baseEdbInfoArr {
-		source := bv.Source
-		edbInfoId := bv.EdbInfoId
-		edbCode := bv.EdbCode
-		startDate = bv.StartDate
-		sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
-		if err != nil {
-			return err
-		}
-		startDate = sTime.Format(utils.FormatDate)
-
-		if source == utils.DATA_SOURCE_THS {
-			err = RefreshEdbDataByThs(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByThs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_WIND {
-			err = RefreshEdbDataByWind(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByWind Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_PB {
-			startDate := sTime.Format(utils.FormatDateUnSpace)
-			endDate := time.Now().Format(utils.FormatDateUnSpace)
-			err = RefreshEdbDataByPb(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByPb Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_MANUAL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByManual(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByManual Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_LZ {
-			err = data_manage.RefreshEdbDataByLz(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByLz Err:" + err.Error()
-			}
-		}else if source == utils.DATA_SOURCE_LT {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLt(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLT Err:" + err.Error()
-			}
-		}
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-	}
-
-	//全部改成重新计算逻辑
-
-	endDate = "" //计算指标不限制结束日期
-
-	for _, v := range calculateArr {
-		edbInfo := calculateMap[v]
-		if edbInfo == nil {
-			fmt.Println("edbInfo is nil:")
-			return err
-		}
-		edbInfoId := edbInfo.EdbInfoId
-		edbCode := edbInfo.EdbCode
-		if edbInfo.Source == utils.DATA_SOURCE_CALCULATE {
-
-			startDate = edbInfo.StartDate
-			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-			if err != nil {
-				return err
-			}
-			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			err = RefreshCalculate(edbInfoList, int(edbInfoId), edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			year := time.Now().Year()
-			startDate = strconv.Itoa(year) + "-01" + "-01"
-
-			err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			//startDate = calculateTbz.StartDate //time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_HBZ { //环比
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateHbz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_HCZ { //环差
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateHcz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_BP { //变频
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateBp Err:" + err.Error()
-				return err
-			}
-		}
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbCode)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error())
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				fmt.Println("ModifyEdbInfoMaxAndMinInfo:" + err.Error())
-				return err
-			}
-		}
-	}
-
-	/*for _, v := range calculateArr {
-		edbInfo := calculateMap[v]
-		if edbInfo == nil {
-			fmt.Println("edbInfo is nil:")
-			return err
-		}
-		edbInfoId := edbInfo.EdbInfoId
-		edbCode := edbInfo.EdbCode
-		if edbInfo.Source == utils.DATA_SOURCE_CALCULATE {
-
-			startDate = edbInfo.StartDate
-			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-			if err != nil {
-				return err
-			}
-			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			err = RefreshCalculate(edbInfoList, int(edbInfoId), edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			year := time.Now().Year()
-			startDate = strconv.Itoa(year) + "-01" + "-01"
-
-			err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			//startDate = calculateTbz.StartDate //time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_HBZ { //环比
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateHbz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_HCZ { //环差
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateHcz(edbInfoId, edbInfo.Source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_BP { //变频
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-
-			err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateBp Err:" + err.Error()
-				return err
-			}
-		}
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbCode)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error())
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				fmt.Println("ModifyEdbInfoMaxAndMinInfo:" + err.Error())
-				return err
-			}
-		}
-	}*/
-	return err
-}
-
-//刷新基础指标
-func EdbInfoRefreshFromBase(edbInfoId int) (err error) {
-	var errmsg string
-	defer func() {
-		if err != nil {
-			fmt.Println("EdbInfoRefreshFromBase Err:" + err.Error() + ";errmsg:" + errmsg)
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
-		}
-	}()
-
-	calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
-	}
-	baseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-	calculateInfoArr := make([]*data_manage.EdbInfo, 0)
-	baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
-	if err != nil {
-		return errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
-	}
-	baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
-
-	for _, v := range calculateList {
-		getBaseEdbInfoArr, getCalculateInfoArr, err := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
-		if err != nil {
-			fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
-			errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
-			return err
-		}
-		baseEdbInfoArr = append(baseEdbInfoArr, getBaseEdbInfoArr...)
-		calculateInfoArr = append(calculateInfoArr, getCalculateInfoArr...)
-		calculateInfoArr = append(calculateInfoArr, v)
-	}
-	//取重
-	newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-	baseMap := make(map[int]int)
-	for _, v := range baseEdbInfoArr {
-		if _, ok := baseMap[v.EdbInfoId]; !ok {
-			newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
-		}
-		baseMap[v.EdbInfoId] = v.EdbInfoId
-	}
-
-	var calculateArr []int
-	newCalculateMap := make(map[int]*data_manage.EdbInfo)
-	for _, v := range calculateInfoArr {
-		if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
-			calculateArr = append(calculateArr, v.EdbInfoId)
-		}
-		newCalculateMap[v.EdbInfoId] = v
-	}
-	sort.Ints(calculateArr)
-	var startDate string
-	for _, bv := range newBaseEdbInfoArr {
-		source := bv.Source
-		edbInfoId := bv.EdbInfoId
-		edbCode := bv.EdbCode
-
-		sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
-		if err != nil {
-			return err
-		}
-		startDate = sTime.Format(utils.FormatDate)
-
-		if source == utils.DATA_SOURCE_THS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = RefreshEdbDataByThs(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByThs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_WIND {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = RefreshEdbDataByWind(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByWind Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_PB {
-			startDate := sTime.Format(utils.FormatDateUnSpace)
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
-			err = RefreshEdbDataByPb(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByPb Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_MANUAL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByManual(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByManual Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_LZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByLz(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByLz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_YS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByLz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_GL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByGl(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshEdbDataByGl Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_ZZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByZz(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByZz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_DL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByDl(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByDl Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_SH {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataBySh(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataBySh Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_CFFEX {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByCffex(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByCffex Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_SHFE {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshEdbDataByShfe(edbInfoId, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByShfe Err:" + err.Error()
-			}
-		}else if source == utils.DATA_SOURCE_LT {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLt(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLT Err:" + err.Error()
-			}
-		}
-
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil {
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	endDate := "" //计算指标不限制结束日期
-	for _, v := range calculateArr {
-		edbInfo := newCalculateMap[v]
-		if edbInfo == nil {
-			return err
-		}
-		edbInfoId := edbInfo.EdbInfoId
-		edbCode := edbInfo.EdbCode
-		source := edbInfo.Source
-		if source == utils.DATA_SOURCE_CALCULATE {
-			startDate = edbInfo.StartDate
-			if startDate == "" {
-				err = errors.New("运算指标更新开始日期不能为空")
-				return err
-			}
-			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-			if err != nil {
-				fmt.Println("time.Parse Err:" + err.Error())
-				return err
-			}
-			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			err = RefreshCalculate(edbInfoList, int(edbInfoId), edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			year := time.Now().Year()
-			startDate = strconv.Itoa(year) + "-01" + "-01"
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			fmt.Println("刷新计算指标:", edbInfoId)
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateBpDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = time.Now().AddDate(-1, -2, 0).Format(utils.FormatDate)
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateBp Err:" + err.Error()
-				return err
-			}
-		}
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil {
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	return err
-}
-
-//全部刷新指标
-func EdbInfoRefreshAllFromBase(edbInfoId int) (err error) {
-	var errmsg string
-	defer func() {
-		if err != nil {
-			fmt.Println("EdbInfoRefreshAllFromBase Err:" + err.Error() + ";errmsg:" + errmsg)
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
-		}
-	}()
-
-	calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		return errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
-	}
-	baseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-	calculateInfoArr := make([]*data_manage.EdbInfo, 0)
-	baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
-	if err != nil {
-		return errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
-	}
-	baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
-
-	switch baseEdbInfo.EdbType {
-	case 1: //基础指标
-		baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
-	case 2: //计算指标
-		calculateList = append(calculateList, baseEdbInfo)
-
-	}
-
-	for _, v := range calculateList {
-		getBaseEdbInfoArr, getCalculateInfoArr, err := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
-		if err != nil {
-			fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
-			errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
-			return err
-		}
-		baseEdbInfoArr = append(baseEdbInfoArr, getBaseEdbInfoArr...)
-		calculateInfoArr = append(calculateInfoArr, getCalculateInfoArr...)
-		calculateInfoArr = append(calculateInfoArr, v)
-	}
-	//取重
-	newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-	baseMap := make(map[int]int)
-	for _, v := range baseEdbInfoArr {
-		if _, ok := baseMap[v.EdbInfoId]; !ok {
-			newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
-		}
-		baseMap[v.EdbInfoId] = v.EdbInfoId
-	}
-
-	var calculateArr []int
-	newCalculateMap := make(map[int]*data_manage.EdbInfo)
-	for _, v := range calculateInfoArr {
-		if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
-			calculateArr = append(calculateArr, v.EdbInfoId)
-		}
-		newCalculateMap[v.EdbInfoId] = v
-	}
-	sort.Ints(calculateArr)
-	var startDate string
-	for _, bv := range newBaseEdbInfoArr {
-		source := bv.Source
-		edbInfoId := bv.EdbInfoId
-		edbCode := bv.EdbCode
-
-		sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
-		if err != nil {
-			return err
-		}
-		startDate = sTime.Format(utils.FormatDate)
-
-		if source == utils.DATA_SOURCE_THS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByThs(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByThs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_WIND {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByWind(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByWind Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_PB {
-			startDate := sTime.Format(utils.FormatDateUnSpace)
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
-			err = data_manage.RefreshAllEdbDataByPb(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByPb Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_MANUAL {
-			err = data_manage.RefreshAllEdbDataByManual(edbInfoId, source, edbCode)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByManual Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_LZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLz(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_YS {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByYs Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_GL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByGl(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByGl Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_ZZ {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByZz(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByZz Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_DL {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByDl(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByDl Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_SH {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataBySh(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataBySh Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_CFFEX {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByCffex(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByCffex Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_SHFE {
-			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByShfe(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByShfe Err:" + err.Error()
-			}
-		}else if source == utils.DATA_SOURCE_LT {
-			endDate := time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllEdbDataByLt(edbInfoId, source, edbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllEdbDataByLT Err:" + err.Error()
-			}
-		}
-
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil {
-			return err
-		}
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-		fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
-	}
-
-	endDate := "" //计算指标不限制日期
-	//刷新相关计算指标
-	for _, v := range calculateArr {
-		edbInfo := newCalculateMap[v]
-		if edbInfo == nil {
-			return err
-		}
-		edbInfoId := edbInfo.EdbInfoId
-		source := edbInfo.Source
-		edbCode := edbInfo.EdbCode
-
-		if source == utils.DATA_SOURCE_CALCULATE {
-			startDate = edbInfo.StartDate
-			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-			if err != nil {
-				return err
-			}
-			startDate = sTime.Format(utils.FormatDate)
-
-			var edbInfoIdBytes []string
-			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-				return err
-			}
-			var formulaStr string
-			edbInfoList := make([]*data_manage.EdbInfo, 0)
-
-			for _, v := range calculateMap {
-				formulaStr += v.FromTag + ","
-				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-				edbInfoList = append(edbInfoList, edbInfo)
-			}
-			err = data_manage.RefreshAllCalculate(edbInfoList, int(edbInfoId), source, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-			if err != nil {
-				errmsg = "RefreshCalculate Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateLjzzy(edbInfoId, source, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateLjzzy Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateTbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateTbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateTcz(edbInfoId, source, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			startDate = edbInfo.StartDate
-			err = data_manage.RefreshAllCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode, startDate)
-			if err != nil {
-				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshAllCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-			if err != nil {
-				errmsg = "RefreshAllCalculateHbz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
-			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-			err = data_manage.RefreshAllCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-			if err != nil {
-				errmsg = "RefreshAllCalculateHcz Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
-			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshAllCalculateBp(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-			if err != nil {
-				errmsg = "RefreshAllCalculateBp Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
-			calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-				return err
-			}
-			fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
-			if err != nil {
-				errmsg = "GetEdbInfoById Err:" + err.Error()
-				return err
-			}
-			startDate = edbInfo.StartDate
-			endDate = time.Now().Format(utils.FormatDate)
-			formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
-			err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, startDate, endDate, calculate.MoveFrequency)
-			if err != nil {
-				errmsg = "RefreshAllCalculateTimeShift Err:" + err.Error()
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
-			err = data_manage.RefreshAllCalculateZjpj(edbInfo)
-			if err != nil {
-				errmsg = "RefreshAllCalculateZjpj Err:" + err.Error()
-				return err
-			}
-		} else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
-			err = data_manage.RefreshAllCalculateLjztbpj(edbInfo)
-			if err != nil {
-				errmsg = "RefreshAllCalculateLjztbpj Err:" + err.Error()
-				return err
-			}
-		}
-
-		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-		if err != nil {
-			return err
-		}
-
-		if maxAndMinItem != nil {
-			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-			if err != nil {
-				return err
-			}
-		}
-		fmt.Println("end calculateArr:", v, time.Now())
-	}
-	return err
-}
-
-// AddEdbInfo 新增手工指标数据
-func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int) (err error) {
-	tradeCode, err := models.GetMaxTradeCode()
-	if err != nil {
-		return
-	}
-
-	if tradeCode == "" {
-		err = errors.New("最大编码为空")
-		return
-	}
-	maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
-	if err != nil {
-		err = errors.New("获取编码信息失败,Err:" + err.Error())
-		return
-	}
-	if maxTradeCode == "" {
-		err = errors.New("编码为空,请联系技术")
-		return
-	}
-	//判断指标名称是否为空
-	if secName == "" {
-		err = errors.New("指标名称不能为空")
-		return
-	}
-	item, err := models.GetEdbinfoBySecName(secName)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		err = errors.New("获取信息失败,Err:" + err.Error())
-		return
-	}
-	if item != nil {
-		err = errors.New("指标名称已存在")
-		return
-	}
-	err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId)
-	if err != nil {
-		err = errors.New("新增失败,Err:" + err.Error())
-		return
-	}
-	err = models.AddEdbinfoUser(maxTradeCode, mobile)
-	return
-}
-
-//全部刷新指标
-//func EdbInfoRefreshAllFromBase(edbInfoId int) (err error) {
-//	var errmsg string
-//	defer func() {
-//		if err != nil {
-//			fmt.Println("EdbInfoRefreshAllFromBase Err:" + err.Error() + ";errmsg:" + errmsg)
-//			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
-//		}
-//	}()
-//
-//	calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
-//	if err != nil && err.Error() != utils.ErrNoRow() {
-//		return errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
-//	}
-//	baseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-//	calculateInfoArr := make([]*data_manage.EdbInfo, 0)
-//	baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
-//	if err != nil {
-//		return errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
-//	}
-//	baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
-//
-//	for _, v := range calculateList {
-//		getBaseEdbInfoArr, getCalculateInfoArr, err := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
-//		if err != nil {
-//			fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
-//			errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
-//			return err
-//		}
-//		baseEdbInfoArr = append(baseEdbInfoArr, getBaseEdbInfoArr...)
-//		calculateInfoArr = append(calculateInfoArr, getCalculateInfoArr...)
-//		calculateInfoArr = append(calculateInfoArr, v)
-//	}
-//	//取重
-//	newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
-//	baseMap := make(map[int]int)
-//	for _, v := range baseEdbInfoArr {
-//		if _, ok := baseMap[v.EdbInfoId]; !ok {
-//			newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
-//		}
-//		baseMap[v.EdbInfoId] = v.EdbInfoId
-//	}
-//
-//	var calculateArr []int
-//	newCalculateMap := make(map[int]*data_manage.EdbInfo)
-//	for _, v := range calculateInfoArr {
-//		if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
-//			calculateArr = append(calculateArr, v.EdbInfoId)
-//		}
-//		newCalculateMap[v.EdbInfoId] = v
-//	}
-//	sort.Ints(calculateArr)
-//	var startDate string
-//	for _, bv := range newBaseEdbInfoArr {
-//		source := bv.Source
-//		edbInfoId := bv.EdbInfoId
-//		edbCode := bv.EdbCode
-//
-//		sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
-//		if err != nil {
-//			return err
-//		}
-//		startDate = sTime.Format(utils.FormatDate)
-//
-//		if source == utils.DATA_SOURCE_THS {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByThs(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByThs Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_WIND {
-//			endDate := time.Now().Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByWind(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByWind Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_PB {
-//			startDate := sTime.Format(utils.FormatDateUnSpace)
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
-//			err = data_manage.RefreshAllEdbDataByPb(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByPb Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_MANUAL {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByManual(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByManual Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_LZ {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByLz(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByLz Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_YS {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByYs Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_GL {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByGl(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByGl Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_ZZ {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByZz(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByZz Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_DL {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByDl(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByDl Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_SH {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataBySh(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataBySh Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_CFFEX {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByCffex(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByCffex Err:" + err.Error()
-//			}
-//		} else if source == utils.DATA_SOURCE_SHFE {
-//			endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-//			err = data_manage.RefreshAllEdbDataByShfe(edbInfoId, source, edbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllEdbDataByShfe Err:" + err.Error()
-//			}
-//		}
-//
-//		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-//		if err != nil {
-//			return err
-//		}
-//		if maxAndMinItem != nil {
-//			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-//			if err != nil {
-//				return err
-//			}
-//		}
-//		fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
-//	}
-//
-//	endDate := "" //计算指标不限制日期
-//	//刷新相关计算指标
-//	for _, v := range calculateArr {
-//		edbInfo := newCalculateMap[v]
-//		if edbInfo == nil {
-//			return err
-//		}
-//		edbInfoId := edbInfo.EdbInfoId
-//		source := edbInfo.Source
-//		edbCode := edbInfo.EdbCode
-//
-//		if source == utils.DATA_SOURCE_CALCULATE {
-//			startDate = edbInfo.StartDate
-//			sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
-//			if err != nil {
-//				return err
-//			}
-//			startDate = sTime.Format(utils.FormatDate)
-//
-//			var edbInfoIdBytes []string
-//			calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
-//				return err
-//			}
-//			var formulaStr string
-//			edbInfoList := make([]*data_manage.EdbInfo, 0)
-//
-//			for _, v := range calculateMap {
-//				formulaStr += v.FromTag + ","
-//				edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
-//				edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
-//				edbInfoList = append(edbInfoList, edbInfo)
-//			}
-//			err = data_manage.RefreshAllCalculate(edbInfoList, int(edbInfoId), source, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
-//			if err != nil {
-//				errmsg = "RefreshCalculate Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
-//			calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			err = data_manage.RefreshAllCalculateLjzzy(edbInfoId, source, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateLjzzy Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
-//			calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			err = data_manage.RefreshAllCalculateTbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateTbz Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
-//			calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			err = data_manage.RefreshAllCalculateTcz(edbInfoId, source, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshCalculateTcz Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
-//			calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-//			startDate = edbInfo.StartDate
-//			err = data_manage.RefreshAllCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode, startDate)
-//			if err != nil {
-//				errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
-//			calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-//			err = data_manage.RefreshAllCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateHbz Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
-//			calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
-//			err = data_manage.RefreshAllCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateHcz Err:" + err.Error()
-//				return err
-//			}
-//		} else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
-//			calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			err = data_manage.RefreshAllCalculateBp(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateBp Err:" + err.Error()
-//				return err
-//			}
-//<<<<<<< HEAD
-//		} else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
-//			calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
-//				return err
-//			}
-//			fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
-//			if err != nil {
-//				errmsg = "GetEdbInfoById Err:" + err.Error()
-//				return err
-//			}
-//			startDate = edbInfo.StartDate
-//			endDate = time.Now().Format(utils.FormatDate)
-//			formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
-//			err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, startDate, endDate, calculate.MoveFrequency)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateTimeShift Err:" + err.Error()
-//=======
-//		} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
-//			err = data_manage.RefreshAllCalculateZjpj(edbInfo)
-//			if err != nil {
-//				errmsg = "RefreshAllCalculateBp Err:" + err.Error()
-//>>>>>>> 884fd669cc9e91923781680e1890a519c012d38e
-//				return err
-//			}
-//		}
-//
-//		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
-//		if err != nil {
-//			return err
-//		}
-//
-//		if maxAndMinItem != nil {
-//			err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
-//			if err != nil {
-//				return err
-//			}
-//		}
-//		fmt.Println("end calculateArr:", v, time.Now())
-//	}
-//	return err
-//}
-//
-//// AddEdbInfo 新增手工指标数据
-//func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int) (err error) {
-//	tradeCode, err := models.GetMaxTradeCode()
-//	if err != nil {
-//		return
-//	}
-//
-//	if tradeCode == "" {
-//		err = errors.New("最大编码为空")
-//		return
-//	}
-//	maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
-//	if err != nil {
-//		err = errors.New("获取编码信息失败,Err:" + err.Error())
-//		return
-//	}
-//	if maxTradeCode == "" {
-//		err = errors.New("编码为空,请联系技术")
-//		return
-//	}
-//	//判断指标名称是否为空
-//	if secName == "" {
-//		err = errors.New("指标名称不能为空")
-//		return
-//	}
-//	item, err := models.GetEdbinfoBySecName(secName)
-//	if err != nil && err.Error() != utils.ErrNoRow() {
-//		err = errors.New("获取信息失败,Err:" + err.Error())
-//		return
-//	}
-//	if item != nil {
-//		err = errors.New("指标名称已存在")
-//		return
-//	}
-//	err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId)
-//	if err != nil {
-//		err = errors.New("新增失败,Err:" + err.Error())
-//		return
-//	}
-//	err = models.AddEdbinfoUser(maxTradeCode, mobile)
-//	return
-//}
-//
-//
-//
-//

+ 0 - 355
services/data/edb_info_calculate.go

@@ -1,355 +0,0 @@
-package data
-
-import (
-	"errors"
-	"fmt"
-	"github.com/yidane/formula"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"strconv"
-	"strings"
-	"time"
-)
-
-func CheckFormula(formula string) map[string]string {
-	mathFormula := []string{"MAX", "MIN", "ABS", "ACOS", "ASIN", "CEIL", "MOD", "POW", "ROUND", "SIGN", "SIN", "TAN", "LOG10", "LOG2", "LOG"}
-
-	str := strings.ToUpper(formula)
-	for _, v := range mathFormula {
-		str = strings.Replace(str, v, "", -1)
-	}
-	str = strings.Replace(str, "(", "", -1)
-	str = strings.Replace(str, ")", "", -1)
-
-	byteMap := make(map[string]string)
-	for i := 0; i < len(str); i++ {
-		byteInt := str[i]
-		if byteInt >= 65 && byteInt <= 90 {
-			byteStr := string(byteInt)
-			if _, ok := byteMap[byteStr]; !ok {
-				byteMap[byteStr] = byteStr
-			}
-		}
-	}
-	return byteMap
-}
-
-type CalculateItems struct {
-	EdbInfoId int
-	DataMap   map[string]float64
-}
-
-func Calculate(edbInfoIdArr []*data_manage.EdbInfo, edbInfoId int, edbCode, formulaStr string, edbInfoIdBytes []string) (err error) {
-	defer func() {
-		if err != nil {
-			utils.FileLog.Info("Calculate Err:%s" + err.Error())
-		}
-	}()
-	saveDataMap := make(map[string]map[int]float64)
-	for _, v := range edbInfoIdArr {
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, v.EdbInfoId)
-		dataList, err := data_manage.GetEdbDataListAll(condition, pars, v.Source, 1)
-		if err != nil {
-			return err
-		}
-		dataMap := make(map[string]float64)
-		for _, dv := range dataList {
-			if val, ok := saveDataMap[dv.DataTime]; ok {
-				if _, ok := val[v.EdbInfoId]; !ok {
-					val[v.EdbInfoId] = dv.Value
-				}
-			} else {
-				temp := make(map[int]float64)
-				temp[v.EdbInfoId] = dv.Value
-				saveDataMap[dv.DataTime] = temp
-			}
-		}
-		item := new(CalculateItems)
-		item.EdbInfoId = v.EdbInfoId
-		item.DataMap = dataMap
-	}
-	formulaMap := CheckFormula(formulaStr)
-	addSql := ` INSERT INTO edb_data_calculate(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	var isAdd bool
-	for sk, sv := range saveDataMap {
-		formulaStr = strings.ToUpper(formulaStr)
-		formulaFormStr := ReplaceFormula(edbInfoIdArr, sv, formulaMap, formulaStr, edbInfoIdBytes)
-		if formulaStr == "" {
-			return
-		}
-		if formulaFormStr != "" {
-			expression := formula.NewExpression(formulaFormStr)
-			calResult, err := expression.Evaluate()
-			if err != nil {
-				err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-			calVal, err := calResult.Float64()
-			if err != nil {
-				err = errors.New("计算失败:获取计算值失败 Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-
-			//需要存入的数据
-			{
-				dataTime, _ := time.Parse(utils.FormatDate, sk)
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				addSql += "("
-				addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + sk + "'" + "," + utils.SubFloatToString(calVal, 4) + "," + "'" + nowStr + "'" +
-					"," + "'" + nowStr + "'" + "," + "1"
-				addSql += "," + "'" + timeStr + "'"
-				addSql += "),"
-				isAdd = true
-			}
-		} else {
-			fmt.Println("formulaFormStr is empty")
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		data_manage.AddEdbDataCalculateBySql(addSql)
-		if err != nil {
-			fmt.Println("AddEdbDataCalculate Err:" + err.Error())
-			return err
-		}
-	}
-	return
-}
-
-func ReplaceFormula(edbInfoIdArr []*data_manage.EdbInfo, valArr map[int]float64, formulaMap map[string]string, formulaStr string, edbInfoIdBytes []string) string {
-	funMap := GetFormulaMap()
-	for k, v := range funMap {
-		formulaStr = strings.Replace(formulaStr, k, v, -1)
-	}
-	replaceCount := 0
-	for dk, dv := range edbInfoIdArr {
-		if dk == 0 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				} else {
-					fmt.Println("valArr not found:", valArr, valOk)
-				}
-			} else {
-				fmt.Println("formulaMap not found:", dKey, dk)
-			}
-		}
-		if dk == 1 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				} else {
-					fmt.Println("valArr not found:", valArr, valOk)
-				}
-			} else {
-				fmt.Println("formulaMap not found:", dKey, dk)
-			}
-		}
-		if dk == 2 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 3 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 4 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 5 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 6 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 7 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-		if dk == 8 {
-			dKey := edbInfoIdBytes[dk]
-			if _, ok := formulaMap[dKey]; ok { //公式中存在
-				if val, valOk := valArr[dv.EdbInfoId]; valOk { //值存在
-					dvStr := fmt.Sprintf("%v", val)
-					formulaStr = strings.Replace(formulaStr, dKey, dvStr, -1)
-					replaceCount++
-				}
-			}
-		}
-	}
-	for k, v := range funMap {
-		formulaStr = strings.Replace(formulaStr, v, k, -1)
-	}
-	if replaceCount == len(formulaMap) {
-		return formulaStr
-	} else {
-		return ""
-	}
-}
-
-func GetFormulaMap() map[string]string {
-	funMap := make(map[string]string)
-	funMap["MAX"] = "[@@]"
-	funMap["MIN"] = "[@!]"
-	funMap["ABS"] = "[@#]"
-	funMap["CEIL"] = "[@$]"
-	funMap["COS"] = "[@%]"
-	funMap["FLOOR"] = "[@^]"
-	funMap["MOD"] = "[@&]"
-	funMap["POW"] = "[@*]"
-	funMap["ROUND"] = "[@(]"
-	return funMap
-}
-
-//刷新数据
-func RefreshCalculate(edbInfoIdArr []*data_manage.EdbInfo, edbInfoId int, edbCode, formulaStr, startDate, endDate string, edbInfoIdBytes []string) (err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println("RefreshCalculate:Err " + err.Error())
-			utils.FileLog.Info("Calculate Err:%s" + err.Error())
-		}
-	}()
-	saveDataMap := make(map[string]map[int]float64)
-	for _, v := range edbInfoIdArr {
-		var condition string
-		var pars []interface{}
-		condition += " AND edb_info_id=? "
-		pars = append(pars, v.EdbInfoId)
-		if startDate != "" {
-			condition += " AND data_time>=? "
-			pars = append(pars, startDate)
-		}
-		if endDate != "" {
-			condition += " AND data_time<=? "
-			pars = append(pars, endDate)
-		}
-		dataList, err := data_manage.GetEdbDataListAll(condition, pars, v.Source, 1)
-		if err != nil {
-			return err
-		}
-		dataMap := make(map[string]float64)
-		for _, dv := range dataList {
-			if val, ok := saveDataMap[dv.DataTime]; ok {
-				if _, ok := val[v.EdbInfoId]; !ok {
-					val[v.EdbInfoId] = dv.Value
-				}
-			} else {
-				temp := make(map[int]float64)
-				temp[v.EdbInfoId] = dv.Value
-				saveDataMap[dv.DataTime] = temp
-			}
-		}
-		item := new(CalculateItems)
-		item.EdbInfoId = v.EdbInfoId
-		item.DataMap = dataMap
-	}
-
-	formulaMap := CheckFormula(formulaStr)
-	addSql := ` INSERT INTO edb_data_calculate(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
-	nowStr := time.Now().Format(utils.FormatDateTime)
-	var isAdd bool
-
-	for sk, sv := range saveDataMap {
-		formulaStr = strings.ToUpper(formulaStr)
-		formulaFormStr := ReplaceFormula(edbInfoIdArr, sv, formulaMap, formulaStr, edbInfoIdBytes)
-		if formulaFormStr != "" {
-			utils.FileLog.Info("formulaFormStr:%s", formulaFormStr)
-			expression := formula.NewExpression(formulaFormStr)
-			calResult, err := expression.Evaluate()
-			if err != nil {
-				err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-			calVal, err := calResult.Float64()
-			if err != nil {
-				err = errors.New("计算失败:获取计算值失败 Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
-				fmt.Println(err)
-				return err
-			}
-
-			count, err := data_manage.GetEdbDataCalculateByCodeAndDate(edbCode, sk)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				return err
-			}
-			if count <= 0 { //需要存入的数据
-				dataTime, _ := time.Parse(utils.FormatDate, sk)
-				timestamp := dataTime.UnixNano() / 1e6
-				timeStr := fmt.Sprintf("%d", timestamp)
-				addSql += "("
-				addSql += strconv.Itoa(edbInfoId) + "," + "'" + edbCode + "'" + "," + "'" + sk + "'" + "," + utils.SubFloatToString(calVal, 4) + "," + "'" + nowStr + "'" +
-					"," + "'" + nowStr + "'" + "," + "1"
-				addSql += "," + "'" + timeStr + "'"
-				addSql += "),"
-				isAdd = true
-			} else {
-				calVal = utils.FixFloat(calVal, 4)
-				err = data_manage.ModifyEdbDataCalculate(int64(edbInfoId), sk, calVal)
-				if err != nil {
-					return err
-				}
-			}
-		}
-	}
-	if isAdd {
-		addSql = strings.TrimRight(addSql, ",")
-		data_manage.AddEdbDataCalculateBySql(addSql)
-		if err != nil {
-			fmt.Println("AddEdbDataCalculate Err:" + err.Error())
-			return err
-		}
-	}
-	return
-}

+ 0 - 127
services/data/edb_info_elastic.go

@@ -1,127 +0,0 @@
-package data
-
-import (
-	"context"
-	"fmt"
-	"github.com/olivere/elastic/v7"
-	"hongze/hongze_chart_lib/models/data_manage"
-	"hongze/hongze_chart_lib/utils"
-	"log"
-	"os"
-	"strconv"
-	"strings"
-)
-
-const (
-	ES_URL      = "http://es-cn-nif227b580019rgw6.public.elasticsearch.aliyuncs.com:9200" //<1>
-	ES_USERNAME = "elastic"                                                               //<2>
-	ES_PASSWORD = "hongze@2021"                                                           //<3>
-)
-
-func NewClient() (client *elastic.Client, err error) {
-	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
-	file := ""
-	if utils.RunMode == "release" {
-		file = `./rdlucklog/eslog.log`
-	} else {
-		file = `./rdlucklog/eslog.log`
-	}
-	logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
-	client, err = elastic.NewClient(
-		elastic.SetURL(ES_URL),
-		elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
-		elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
-		elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
-	return
-}
-
-
-//indexName:索引名称
-//mappingJson:表结构
-func EsCreateIndex(indexName, mappingJson string) (err error) {
-	client, err := NewClient()
-	if err != nil {
-		return
-	}
-	//定义表结构
-	exists, err := client.IndexExists(indexName).Do(context.Background()) //<5>
-	if err != nil {
-		return
-	}
-	if !exists {
-		resp, err := client.CreateIndex(indexName).BodyJson(mappingJson).Do(context.Background())
-		//BodyJson(bodyJson).Do(context.Background())
-		if err != nil {
-			fmt.Println("CreateIndex Err:" + err.Error())
-			return err
-		}
-		fmt.Println(resp.Index, resp.ShardsAcknowledged, resp.Acknowledged)
-	} else {
-		fmt.Println(indexName + " 已存在")
-	}
-	return
-}
-
-func AddAllEdbInfo() {
-	allList, err := data_manage.GetEdbInfoAllList()
-	if err != nil {
-		fmt.Println("GetArticleAll Err:", err.Error())
-		return
-	}
-	indexName := "hz_data_lib_v1"
-	for _, v := range allList {
-		EsAddOrEditEdbInfo(indexName, strconv.Itoa(v.EdbInfoId), v)
-		fmt.Println(v.EdbInfoId)
-	}
-}
-
-//新增和修改数据
-func EsAddOrEditEdbInfo(indexName, docId string, item *data_manage.EdbInfo) (err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println("EsAddOrEditEdbInfo Err:", err.Error())
-		}
-	}()
-	client, err := NewClient()
-	if err != nil {
-		return
-	}
-	searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
-	if err != nil && !strings.Contains(err.Error(), "404") {
-		fmt.Println("Get Err" + err.Error())
-		return
-	}
-	if searchById != nil && searchById.Found {
-		resp, err := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
-			"EdbInfoId":  item.EdbInfoId,
-			"EdbCode":    item.EdbCode,
-			"EdbName":    item.EdbName,
-			"Frequency":  item.Frequency,
-			"SourceName": item.SourceName,
-			"UniqueCode": item.UniqueCode,
-			"Unit":       item.Unit,
-		}).Do(context.Background())
-		if err != nil {
-			return err
-		}
-		fmt.Println(resp.Status, resp.Result)
-		if resp.Status == 0 {
-			fmt.Println("修改成功")
-		} else {
-			fmt.Println("EditData", resp.Status, resp.Result)
-		}
-	} else {
-		resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
-		if err != nil {
-			fmt.Println("新增失败:", err.Error())
-			return err
-		}
-		if resp.Status == 0 && resp.Result == "created" {
-			fmt.Println("新增成功")
-			err = nil
-		} else {
-			fmt.Println("AddData", resp.Status, resp.Result)
-		}
-	}
-	return
-}

+ 9 - 0
utils/config.go

@@ -18,6 +18,11 @@ var (
 	Re          error        //redis错误
 )
 
+// 经济数据库
+var (
+	EDB_LIB_URL string
+)
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -57,9 +62,13 @@ func init() {
 
 		//同花顺,万得接口服务地址(阿里云windows服务器地址;内网地址)
 		Hz_Server_Data_Url = "http://172.19.173.231:7000/"
+
+		EDB_LIB_URL = "http://172.19.173.232:8300/edbapi/"
 	} else {
 		//同花顺,万得接口服务地址(阿里云windows服务器地址;外网地址)
 		Hz_Server_Data_Url = "http://139.196.136.213:7000/"
+
+		EDB_LIB_URL = "http://8.136.199.33:8300/edbapi/"
 	}
 }
 

+ 8 - 1
utils/constants.go

@@ -57,6 +57,7 @@ const (
 	DATA_SOURCE_CALCULATE_ZJPJ                  //直接拼接->23
 	DATA_SOURCE_CALCULATE_LJZTBPJ               //累计值同比拼接->24
 	DATA_SOURCE_LT                              //路透->25
+	DATA_SOURCE_COAL                            //煤炭网->26
 )
 
 //数据刷新频率
@@ -88,4 +89,10 @@ const (
 
 var (
 	Hz_Server_Data_Url string //同花顺,万得接口服务地址(阿里云windows服务器地址)
-)
+)
+
+//EDB_LIB
+var (
+	APP_EDB_LIB_NAME_EN = "hongze_edb_lib"
+	EDB_LIB_Md5_KEY     = "GuRaB6dY1bXOJcwG"
+)

+ 43 - 1
utils/logs.go

@@ -1,18 +1,60 @@
 package utils
 
 import (
+	"encoding/json"
 	"github.com/beego/beego/v2/core/logs"
+	"os"
 )
 
 var FileLog *logs.BeeLogger
 var FileLogData *logs.BeeLogger
+var Binlog *logs.BeeLogger
 
 func init() {
 	FileLog = logs.NewLogger(1000000)
 	FileLog.SetLogger(logs.AdapterFile, `{"filename":"./rdlucklog/hongze_chart_lib.log"}`)
 	FileLog.EnableFuncCallDepth(true)
 
-
 	FileLogData = logs.NewLogger(1000000)
 	FileLogData.SetLogger(logs.AdapterFile, `{"filename":"./rdlucklog/hongze_admin_data.log"}`)
+
+	//binlog日志
+	binLogDir := `./binlog`
+	os.MkdirAll(binLogDir, os.ModePerm)
+	Binlog = logs.NewLogger(1000000)
+	logConfig := getDefaultLogConfig()
+	logConfig.FileName = "./binlog/binlog.log"
+	logConfig.MaxLines = 10000000
+	logConfig.Rotate = true
+	b, _ := json.Marshal(logConfig)
+	Binlog.SetLogger(logs.AdapterFile, string(b))
+	Binlog.EnableFuncCallDepth(true)
+
+	//输出在控制台
+	//Binlog.SetLogger(logs.AdapterConsole)
+}
+
+type logConfig struct {
+	FileName string `json:"filename" description:"保存的文件名"`
+	MaxLines int    `json:"maxlines"  description:"每个文件保存的最大行数,默认值 1000000"`
+	MaxSize  int    `json:"maxsize" description:"每个文件保存的最大尺寸,默认值是 1 << 28, //256 MB"`
+	Daily    bool   `json:"daily" description:"是否按照每天 logrotate,默认是 true"`
+	MaxDays  int    `json:"maxdays" description:"文件最多保存多少天,默认保存 7 天"`
+	Rotate   bool   `json:"rotate" description:"是否开启 logrotate,默认是 true"`
+	Level    int    `json:"level" description:"日志保存的时候的级别,默认是 Trace 级别"`
+	Color    bool   `json:"color" description:"日志是否输出颜色"`
+	//Perm     string `json:"perm" description:"日志文件权限"`
+}
+
+func getDefaultLogConfig() logConfig {
+	return logConfig{
+		FileName: "",
+		MaxLines: 0,
+		MaxSize:  1 << 28,
+		Daily:    true,
+		MaxDays:  31,	//我就是喜欢31天,咋滴,不喜欢你就自己改-_-!
+		Rotate:   true,
+		Level:    logs.LevelTrace,
+		//Perm:     "",
+	}
 }

部分文件因为文件数量过多而无法显示