Browse Source

国新增能指标相关功能

- 添加国能指标配置和接口处理
- 实现国能指标数据获取和分页查询
- 新增达梦数据库初始化功能
- 优化代码结构,移除冗余代码
Roc 6 months ago
parent
commit
3babbe5044

+ 10 - 0
config/config.go

@@ -10,6 +10,7 @@ type Config struct {
 	Smm      Smm      `mapstructure:"smm" json:"smm" yaml:"smm"`
 	Xiangyu  Xiangyu  `mapstructure:"xiangyu" json:"xiangyu" yaml:"xiangyu"`
 	PCSG     PCSG     `mapstructure:"pcsg" json:"pcsg" yaml:"pcsg"`
+	Gn       Gn       `mapstructure:"gn" json:"gn" yaml:"gn"`
 }
 
 // Serve gin服务配置
@@ -88,6 +89,7 @@ type OracleJY struct {
 // Business 商家的配置
 type Business struct {
 	JiaYueIndexSyncMinute int `mapstructure:"jiayue-index-sync-minute" json:"jiayue-index-sync-minute" yaml:"jiayue-index-sync-minute" description:"嘉悦同步N分钟前至现在的指标(负数)"`
+	GnIndexSyncMinute     int `mapstructure:"gn-index-sync-minute" json:"gn-index-sync-minute" yaml:"gn-index-sync-minute" description:"国能同步N分钟前至现在的指标(负数)"`
 }
 
 // Smm smm配置
@@ -118,3 +120,11 @@ type Xiangyu struct {
 type PCSG struct {
 	BloombergApiUrl string `mapstructure:"bloomberge-api-url" json:"bloomberge-api-url" yaml:"bloomberge-api-url" description:"彭博API服务地址"`
 }
+
+// Gn 国能的的配置
+type Gn struct {
+	IndexSyncMinute  int    `mapstructure:"index-sync-minute" json:"index-sync-minute" yaml:"index-sync-minute" description:"国能同步N分钟前至现在的指标(负数)"`
+	DataHost         string `mapstructure:"data-host" json:"data-host" yaml:"data-host" description:"数据节点地址"`
+	DataAccessKey    string `mapstructure:"data-access-key" json:"data-access-key" yaml:"data-access-key" description:"数据节点的access_key"`
+	DataAccessSecret string `mapstructure:"data-access-secret" json:"data-access-secret" yaml:"data-access-secret" description:"数据节点的access_secret"`
+}

+ 75 - 0
controller/index_data/gn_index.go

@@ -0,0 +1,75 @@
+package index_data
+
+import (
+	"eta_gn/eta_bridge/controller/resp"
+	"eta_gn/eta_bridge/global"
+	indexDataReq "eta_gn/eta_bridge/models/request/index_data"
+	"eta_gn/eta_bridge/models/response"
+	indexDataService "eta_gn/eta_bridge/services/index_data"
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+)
+
+// GnIndexController 国能指标
+type GnIndexController struct{}
+
+// GetPageIndex
+// @Description 获取国能指标列表-分页
+// @Success 200 {string} string "获取成功"
+// @Router /gn/page_index [post]
+func (j *GnIndexController) GetPageIndex(c *gin.Context) {
+	var req indexDataReq.GnPageIndexReq
+	if e := c.Bind(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+
+	list, page, err := indexDataService.GetPageIndexesFromGn(req.PageIndex, req.PageSize, req.LastModifyTime)
+	if err != nil {
+		resp.FailMsg("查询失败", err.Error(), c)
+		return
+	}
+
+	data := response.GnPageIndexResp{
+		Page: page,
+		List: list,
+	}
+	resp.OkData("操作成功", data, c)
+	return
+}
+
+// GetIndexData
+// @Description 获取国能指标数据
+// @Success 200 {string} string "获取成功"
+// @Router /gn/index_data [post]
+func (j *GnIndexController) GetIndexData(c *gin.Context) {
+	var req indexDataReq.GnDataReq
+	if e := c.Bind(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+	if req.IndexCode == "" {
+		resp.FailMsg("请输入指标code码", "请输入指标code码", c)
+		return
+	}
+
+	data, e := indexDataService.GetIndexAndDataFromGn(req.IndexCode, req.StartDate, req.EndDate)
+	if e != nil {
+		resp.FailMsg("获取失败", "获取国能指标数据失败, err: "+e.Error(), c)
+		return
+	}
+
+	resp.OkData("获取成功", data, c)
+
+	return
+}

+ 0 - 21
controller/index_data/jiayue_index.go

@@ -136,27 +136,6 @@ func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 	return
 }
 
-// GetIndexFrequency
-// @Description 获取指标频度列表
-// @Success 200 {string} string "获取成功"
-// @Router /jiayue/frequency_list [post]
-func (j *JiaYueIndexController) GetIndexFrequency(c *gin.Context) {
-	list, err := jiayue.GetDictFrequency()
-	if err != nil {
-		resp.FailMsg("获取失败", err.Error(), c)
-		return
-	}
-	// 过滤一下空的和斜杠
-	data := make([]string, 0)
-	for _, v := range list {
-		if v != "" && v != "/" {
-			data = append(data, v)
-		}
-	}
-	resp.OkData("获取成功", data, c)
-	return
-}
-
 // GetRecentNewIndex
 // @Description 获取最近新增的指标数据
 // @Success 200 {string} string "获取成功"

+ 3 - 1
core/run_server.go

@@ -17,7 +17,9 @@ func RunServe() {
 	}
 
 	// 初始化mysql数据库
-	init_serve.Mysql()
+	//init_serve.Mysql()
+	// 初始化 达梦数据库
+	init_serve.InitDm()
 
 	if global.CONFIG.OracleJY.Account != "" {
 		//初始化oracle

+ 5 - 5
go.mod

@@ -7,15 +7,19 @@ require (
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/fsnotify/fsnotify v1.6.0
 	github.com/gin-gonic/gin v1.9.1
+	github.com/go-mysql-org/go-mysql v1.7.0
 	github.com/go-playground/locales v0.14.1
 	github.com/go-playground/universal-translator v0.18.1
 	github.com/go-playground/validator/v10 v10.14.0
 	github.com/go-redis/redis/v8 v8.11.5
+	github.com/go-sql-driver/mysql v1.7.0
 	github.com/godror/godror v0.40.3
 	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
 	github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
 	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
+	github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63
 	github.com/rdlucklib/rdluck_tools v1.0.3
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/spf13/viper v1.16.0
 	github.com/swaggo/swag v1.16.1
 	github.com/tealeg/xlsx v1.0.5
@@ -35,17 +39,15 @@ require (
 	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/gabriel-vasile/mimetype v1.4.2 // indirect
-	github.com/garyburd/redigo v1.6.3 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
 	github.com/go-logfmt/logfmt v0.6.0 // indirect
-	github.com/go-mysql-org/go-mysql v1.7.0 // indirect
 	github.com/go-openapi/jsonpointer v0.19.5 // indirect
 	github.com/go-openapi/jsonreference v0.19.6 // indirect
 	github.com/go-openapi/spec v0.20.4 // indirect
 	github.com/go-openapi/swag v0.19.15 // indirect
-	github.com/go-sql-driver/mysql v1.7.0 // indirect
 	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/godror/knownpb v0.1.1 // indirect
+	github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
 	github.com/google/uuid v1.3.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
@@ -63,11 +65,9 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
-	github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
 	github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7 // indirect
 	github.com/pingcap/tidb/parser v0.0.0-20221126021158-6b02a5d8ba7d // indirect
 	github.com/pkg/errors v0.9.1 // indirect
-	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
 	github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 // indirect
 	github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect

+ 14 - 1
go.sum

@@ -106,12 +106,12 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
 github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
+github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
 github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
 github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
 github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
-github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
 github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
@@ -140,6 +140,7 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
 github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
 github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
 github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
+github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
@@ -190,6 +191,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
 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/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
 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=
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -205,6 +207,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 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.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
 github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -260,6 +263,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
 github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
+github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -299,12 +303,16 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
+github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
 github.com/oklog/ulid/v2 v2.0.2 h1:r4fFzBm+bv0wNKNh5eXTwU7i85y5x+uwkxCUTNVQqLc=
+github.com/oklog/ulid/v2 v2.0.2/go.mod h1:mtBL0Qe/0HAx6/a4Z30qxVIAL1eQDweXq5lxOEiwQ68=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
+github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
 github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
 github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
+github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
 github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
@@ -312,6 +320,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
 github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
 github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
 github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
+github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 h1:USx2/E1bX46VG32FIw034Au6seQ2fY9NEILmNh/UlQg=
 github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
 github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
 github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 h1:+FZIDR/D97YOPik4N4lPDaUcLDF/EQPogxtlHB2ZZRM=
@@ -346,6 +355,7 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
 github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
+github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
 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=
@@ -421,6 +431,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
 go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
+go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
 go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
 go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
@@ -486,6 +497,7 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
+golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 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=
@@ -550,6 +562,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
+golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
 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=
 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

+ 135 - 0
init_serve/dm.go

@@ -0,0 +1,135 @@
+package init_serve
+
+import (
+	"database/sql/driver"
+	_ "dm"
+	dm "dmgorm2"
+	"eta_gn/eta_bridge/global"
+	"fmt"
+	"gorm.io/gorm"
+	"gorm.io/gorm/logger"
+	"gorm.io/gorm/schema"
+	"io"
+	"log"
+	"os"
+	"time"
+
+	_ "github.com/go-sql-driver/mysql"
+)
+
+type LocalTime time.Time
+
+// InitDm
+// @Description: 达梦数据库初始化
+func InitDm() {
+	dmSqlMap := make(map[string]*gorm.DB)
+
+	//开启日志
+	logWriter := io.MultiWriter(global.MYSQL_LOG) //binlog日志,记录到文件中去
+	if global.CONFIG.Mysql.Stdout {
+		logWriter = io.MultiWriter(global.MYSQL_LOG, os.Stdout)
+	}
+	newLogger := logger.New(log.New(logWriter, "\r\n", log.LstdFlags), logger.Config{
+		SlowThreshold:             200 * time.Millisecond, //慢sql :200ms
+		LogLevel:                  logger.Info,            //记录的日志类型,info代表所有信息都记录
+		IgnoreRecordNotFoundError: true,                   //是否忽略找不到数据错误信息(只是日志记录记录成err还是普通的输出的区别,并不影响业务代码中的:找不到数据行error)
+		Colorful:                  false,                  //是否颜色输出
+	})
+
+	mysqlConf := global.CONFIG.Mysql
+	if len(mysqlConf.List) <= 0 {
+		global.LOG.Error("mysql链接未配置")
+		panic(fmt.Errorf("mysql链接未配置"))
+	}
+
+	for _, conf := range mysqlConf.List {
+		isDefault := false
+		//默认数据库连接
+		if mysqlConf.DefaultDsnAliasName == conf.AliasName {
+			isDefault = true
+		}
+
+		// 库连接
+		connectDm(conf.Dsn, conf.AliasName, newLogger, dmSqlMap, isDefault)
+
+	}
+
+	//全局赋值数据库链接
+	global.MYSQL = dmSqlMap
+
+}
+
+// connectDm
+// @Description: 达梦数据库连接
+// @param dsn
+// @param aliasName
+// @param newLogger
+// @param dmSqlMap
+// @param isDefault
+func connectDm(dsn, aliasName string, newLogger logger.Interface, dmSqlMap map[string]*gorm.DB, isDefault bool) {
+	//fmt.Println("dsn:", dsn, "  ==  ;aliasName:", aliasName)
+	if dsn == `` {
+		return
+	}
+	//dsn := "dm://SYSDBA:SYSDBA001@8.136.199.33:30236?schema=\"eta_master\""
+	//dsn := "dm://ETA:Han6258199118%60@localhost:5236?schema=ECOLOGY_TARGET"
+	db, err := gorm.Open(dm.Open(dsn), &gorm.Config{
+		Logger: newLogger,
+		NamingStrategy: schema.NamingStrategy{
+			SingularTable: true, // 表示使用单数表名,启用该选项后,GORM 将不会对表名进行复数化处理
+		},
+	})
+	if err != nil {
+		//global.LOG.Errorf("mysql 启动异常,数据库:default;Err:", err)
+		panic(fmt.Errorf("mysql 启动异常,数据库:%s;Err:%s", aliasName, err))
+	}
+	//创建连接池
+	sqlDB, err := db.DB()
+	if err != nil {
+		//global.LOG.Errorf("mysql 创建连接池失败,数据库:default;Err:", err)
+		panic(fmt.Errorf("mysql 创建连接池失败,数据库:%s;Err:%s", aliasName, err))
+	}
+
+	dmSqlMap[aliasName] = db
+
+	//默认数据库连接
+	if isDefault {
+		global.DEFAULT_MYSQL = db
+	}
+
+	// SetMaxIdleConns 设置空闲连接池中连接的最大数量
+	sqlDB.SetMaxIdleConns(50)
+
+	// SetMaxOpenConns 设置打开数据库连接的最大数量。
+	sqlDB.SetMaxOpenConns(100)
+
+	// SetConnMaxLifetime 设置了连接可复用的最大时间。
+	sqlDB.SetConnMaxLifetime(10 * time.Minute)
+
+}
+
+func (t *LocalTime) MarshalJSON() ([]byte, error) {
+	tTime := time.Time(*t)
+	if tTime.IsZero() {
+		return []byte("\"\""), nil
+	}
+	return []byte(fmt.Sprintf("\"%v\"", tTime.Format("2006-01-02 15:04:05"))), nil
+}
+
+func (t LocalTime) Value() (driver.Value, error) {
+	var zeroTime time.Time
+	tlt := time.Time(t)
+	//判断给定时间是否和默认零时间的时间戳相同
+	if tlt.UnixNano() == zeroTime.UnixNano() {
+		return nil, nil
+	}
+	return tlt, nil
+}
+
+func (t *LocalTime) Scan(v interface{}) error {
+	if value, ok := v.(time.Time); ok {
+		*t = LocalTime(value)
+		return nil
+	}
+	return fmt.Errorf("can not convert %v to timestamp", v)
+}

+ 19 - 0
models/gn/index.go

@@ -0,0 +1,19 @@
+package gn
+
+type IndexInfo struct {
+	ClassifyNameOne   string `description:"一级目录"`
+	ClassifyNameTwo   string `description:"二级目录"`
+	ClassifyNameThree string `description:"三级目录"`
+	OriginalEdbCode   string `description:"数据节点指标编码"`
+	EdbCode           string `description:"数据源指标原始编码"`
+	EdbName           string `description:"指标名称"`
+	Frequency         string `description:"频度"`
+	Unit              string `description:"单位"`
+}
+
+// IndexData 指标数据
+type IndexData struct {
+	Val        float64 `json:"val"`
+	DataTime   string  `json:"data_time"`
+	UpdateTime string  `json:"update_time"`
+}

+ 0 - 41
models/jiayue/dict.go

@@ -313,47 +313,6 @@ func getDictData(sqlStatement string, pars []interface{}) (dictData []DictData,
 	return
 }
 
-// GetDictFrequency 获取指标频度
-func GetDictFrequency() (frequencies []string, err error) {
-	defer func() {
-		if err != nil {
-			global.LOG.Info("嘉悦-获取指标频度失败, Err:" + err.Error())
-		}
-	}()
-
-	sqlBase := fmt.Sprintf(`SELECT DISTINCT FREQUENCY FROM %s`, IndexTableName)
-	stmt, e := global.OracleJy.Prepare(sqlBase)
-	if e != nil {
-		err = fmt.Errorf("预处理sql失败, err: %s", e.Error())
-		return
-	}
-	rows, e := stmt.Query()
-	if e != nil {
-		err = fmt.Errorf("查询sql失败, err: %s", e.Error())
-		return
-	}
-	defer func() {
-		_ = rows.Close() // 关闭查询连接
-	}()
-
-	for rows.Next() {
-		var frequency string
-		if e = rows.Scan(&frequency); e != nil {
-			err = fmt.Errorf("扫描错误, err: %s", e.Error())
-			return
-		}
-		frequencies = append(frequencies, frequency)
-	}
-	if e = rows.Err(); e != nil {
-		err = fmt.Errorf("解析行数据失败, err: %s", e.Error())
-		return
-	}
-	defer func() {
-		_ = stmt.Close()
-	}()
-	return
-}
-
 // GetDictIndexCount 获取指标总记录数
 func GetDictIndexCount(condition string, pars []interface{}) (total int, err error) {
 	defer func() {

+ 15 - 0
models/request/index_data/gn_index.go

@@ -0,0 +1,15 @@
+package index_data
+
+// GnPageIndexReq 指标列表请求体-分页
+type GnPageIndexReq struct {
+	LastModifyTime string `json:"last_modify_time" form:"last_modify_time" description:"最近一次更新时间"`
+	PageIndex      int    `json:"page_index" form:"page_index" description:"当前页码"`
+	PageSize       int    `json:"page_size" form:"page_size" description:"每页数据量"`
+}
+
+// GnDataReq 指标数据请求体
+type GnDataReq struct {
+	IndexCode string `json:"index_code" form:"index_code" description:"指标编码"`
+	StartDate string `json:"start_date" form:"start_date" description:"开始日期"`
+	EndDate   string `json:"end_date" form:"end_date" description:"结束日期"`
+}

+ 12 - 0
models/response/gn_index.go

@@ -0,0 +1,12 @@
+package response
+
+import (
+	"eta_gn/eta_bridge/models/gn"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+// GnPageIndexResp 指标分页列表响应体
+type GnPageIndexResp struct {
+	Page *paging.PagingItem `description:"数据分页"`
+	List []gn.IndexInfo     `description:"列表数据"`
+}

+ 4 - 15
routers/index_data.go

@@ -8,19 +8,8 @@ import (
 
 // InitIndexData 获取指标信息
 func InitIndexData(r *gin.RouterGroup) {
-	control := new(index_data.JiaYueIndexController)
-	group := r.Group("index_data/").Use(middleware.InternalToken())
-	group.POST("jiayue/index", control.GetIndex)
-	group.POST("jiayue/index_data", control.GetIndexData)
-	group.POST("jiayue/page_index", control.GetPageIndex)
-	group.POST("jiayue/frequency_list", control.GetIndexFrequency)
-	group.POST("jiayue/new_index", control.GetRecentNewIndex)
-	group.POST("jiayue/menu_list", control.GetMenuList)
-	group.POST("jiayue/build_import_excel", control.BuildImportExcel)
-
-	zhongjiControl := new(index_data.ZhongjiIndexController)
-	zhongjiGroup := r.Group("index_data/zhongji/").Use(middleware.InternalToken())
-	zhongjiGroup.POST("/smm/list", zhongjiControl.GetIndexList)
-	zhongjiGroup.POST("/smm/data", zhongjiControl.GetIndexData)
-	zhongjiGroup.POST("/smm/latest", zhongjiControl.GetIndexDataLatest)
+	gnControl := new(index_data.GnIndexController)
+	gnGroup := r.Group("index_data/gn/").Use(middleware.InternalToken())
+	gnGroup.POST("/edb/list", gnControl.GetPageIndex)
+	gnGroup.POST("/edb/data/list", gnControl.GetIndexData)
 }

File diff suppressed because it is too large
+ 435 - 0
services/index_data/gn_base_data_platform.go


+ 148 - 0
services/index_data/gn_platform.go

@@ -0,0 +1,148 @@
+package index_data
+
+import (
+	"eta_gn/eta_bridge/global"
+	"eta_gn/eta_bridge/models/gn"
+	"eta_gn/eta_bridge/services/alarm_msg"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/shopspring/decimal"
+	"strings"
+)
+
+// GetPageIndexesFromGn 分页获取指标数据
+func GetPageIndexesFromGn(pageIndex, pageSize int, modifyTime string) (list []gn.IndexInfo, page *paging.PagingItem, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("GetPageIndexesFromGn Err: " + err.Error())
+			go alarm_msg.SendAlarmMsg("GetPageIndexesFromGn Err: "+err.Error(), 3)
+			return
+		}
+	}()
+
+	req := IndexInfoReq{
+		UpdateTime: "",
+		Size:       pageSize,
+		PageNo:     pageIndex,
+	}
+	resp, err := GetIndexInfoList(req)
+	if err != nil {
+		return
+	}
+
+	page = paging.GetPaging(resp.Data.PageNo, resp.Data.Size, resp.Data.Total)
+	list = make([]gn.IndexInfo, 0)
+
+	for _, v := range resp.Data.Records {
+		list = append(list, gn.IndexInfo{
+			ClassifyNameOne:   v.INDEXLEVELONE,
+			ClassifyNameTwo:   v.INDEXLEVELTWO,
+			ClassifyNameThree: v.INDEXLEVELTHREE,
+			OriginalEdbCode:   v.INDEXORIGINCODE,
+			EdbCode:           fmt.Sprint(v.INDEXID),
+			EdbName:           v.INDEXORIGINNAME,
+			Frequency:         v.DATAFREQ,
+			Unit:              v.DATAUNIT,
+		})
+	}
+
+	return
+}
+
+// GetIndexAndDataFromGn 获取指标和数据
+func GetIndexAndDataFromGn(indexCode, startDate, endDate string) (list []gn.IndexData, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("GetIndexAndDataFromGn Err: " + err.Error())
+			go alarm_msg.SendAlarmMsg("GetIndexAndDataFromGn Err: "+err.Error(), 3)
+			return
+		}
+	}()
+
+	var dataDate string
+	dateList := make([]string, 0)
+	if startDate != `` {
+		dateList = append(dateList, startDate)
+	}
+	if endDate != `` {
+		dateList = append(dateList, endDate)
+	}
+	if len(dateList) > 0 {
+		dataDate = strings.Join(dateList, ",")
+	}
+
+	req := IndexValueReq{
+		IndexId:  indexCode,
+		DataDate: dataDate,
+		Size:     100,
+		PageNo:   1,
+	}
+
+	list = make([]gn.IndexData, 0)
+	isEnd := false
+
+	for i := 1; !isEnd; i++ {
+		req.PageNo = i
+		tmpList, page, tmpErr := getIndexAndDataFromGn(req)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		list = append(list, tmpList...)
+		isEnd = page.IsEnd
+	}
+
+	return
+}
+
+// getIndexAndDataFromGn
+// @Description: 获取数据
+// @param req
+// @return list
+// @return page
+// @return err
+func getIndexAndDataFromGn(req IndexValueReq) (list []gn.IndexData, page *paging.PagingItem, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("GetIndexAndDataFromGn Err: " + err.Error())
+			go alarm_msg.SendAlarmMsg("GetIndexAndDataFromGn Err: "+err.Error(), 3)
+			return
+		}
+	}()
+
+	resp, err := GetIndexValueList(req)
+	if err != nil {
+		return
+	}
+	page = paging.GetPaging(resp.Data.PageNo, resp.Data.Size, resp.Data.Total)
+
+	list = make([]gn.IndexData, 0)
+
+	for _, v := range resp.Data.Records {
+		// 非数值数据,过滤
+		//脏数据:
+		// 停产
+		// TODO、
+		// 1-2
+		// 空字符串
+
+		// 空数据,过滤
+		if v.VALUE == `` {
+			continue
+		}
+		valF, tmpErr := decimal.NewFromString(v.VALUE)
+		if tmpErr != nil {
+			//err = tmpErr
+			continue
+		}
+		val, _ := valF.Float64()
+
+		list = append(list, gn.IndexData{
+			Val:        val,
+			UpdateTime: v.UPDATETIME,
+			DataTime:   v.DATADATE,
+		})
+	}
+
+	return
+}

+ 12 - 1
utils/common.go

@@ -1090,4 +1090,15 @@ func InArrayByInt(idStrList []int, searchId int) (has bool) {
 		}
 	}
 	return
-}
+}
+
+// InArrayByStr php中的in_array(判断String类型的切片中是否存在该Int值)
+func InArrayByStr(idStrList []string, searchId string) (has bool) {
+	for _, id := range idStrList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}

+ 4 - 3
utils/constants.go

@@ -28,9 +28,10 @@ const (
 )
 
 const (
-	CACHE_CRM_AUTH_CODE_PREFIX = "hz_crm_eta:crm_auth_code_" // 免密登录Code-CRM
-	CACHE_ETA_AUTH_CODE_PREFIX = "hz_crm_eta:eta_auth_code_" // 免密登录Code-ETA
-	CACHE_EDB_SMM_SERVER_TOKEN = "edb:smm_server_token"      //smm调用凭证
+	CACHE_CRM_AUTH_CODE_PREFIX     = "hz_crm_eta:crm_auth_code_" // 免密登录Code-CRM
+	CACHE_ETA_AUTH_CODE_PREFIX     = "hz_crm_eta:eta_auth_code_" // 免密登录Code-ETA
+	CACHE_EDB_SMM_SERVER_TOKEN     = "edb:smm_server_token"      //smm调用凭证
+	CACHE_EDB_GN_DATA_SERVER_TOKEN = "edb:gn_data_server_token"  // 国能数据节点调用凭证
 )
 
 // 管理员,ficc管理员,ficc销售,权益管理员,权益销售。

Some files were not shown because too many files changed in this diff