Explorar o código

获取嘉悦物产指标信息

xyxie hai 1 ano
pai
achega
5c02919408

+ 12 - 4
config/config.go

@@ -1,10 +1,11 @@
 package config
 
 type Config struct {
-	Log   Log   `mapstructure:"log" json:"log" yaml:"log"`
-	Serve Serve `mapstructure:"serve" json:"serve" yaml:"serve"`
-	Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
-	Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
+	Log      Log      `mapstructure:"log" json:"log" yaml:"log"`
+	Serve    Serve    `mapstructure:"serve" json:"serve" yaml:"serve"`
+	Mysql    Mysql    `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
+	Redis    Redis    `mapstructure:"redis" json:"redis" yaml:"redis"`
+	OracleJY OracleJY `mapstructure:"oracle_jy" json:"oracle_jy" yaml:"oracle_jy"`
 }
 
 // Serve gin服务配置
@@ -52,3 +53,10 @@ type Redis struct {
 	Password string `mapstructure:"password" json:"password" yaml:"password" description:"redis服务密码"`
 	Db       int    `mapstructure:"db" json:"db" yaml:"db" description:"默认使用的redis库"`
 }
+
+// OracleJY 嘉悦物产数据库配置
+type OracleJY struct {
+	Conn     string `mapstructure:"conn" json:"conn" yaml:"conn" description:"服务链接地址"`
+	Account  string `mapstructure:"account" json:"account" yaml:"account" description:"oracle数据库账号"`
+	Password string `mapstructure:"password" json:"password" yaml:"password" description:"oracle数据库密码"`
+}

+ 49 - 0
controller/index_data/jiayue_index.go

@@ -0,0 +1,49 @@
+package index_data
+
+import (
+	"eta/eta_bridge/controller/resp"
+	"eta/eta_bridge/global"
+	"eta/eta_bridge/models/request/index_data"
+	"eta/eta_bridge/models/response"
+	index_data_service "eta/eta_bridge/services/index_data"
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+)
+
+type JiaYueIndexController struct{}
+
+// GetData
+// @Description 获取嘉悦指标数据
+// @Success 200 {string} string "操作成功"
+// @Router /jiayue/index [get]
+func (j *JiaYueIndexController) GetData(c *gin.Context) {
+	var req index_data.IndexReq
+	err := c.Bind(&req)
+	if err != nil {
+		errs, ok := err.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+err.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
+		return
+	}
+	if req.IndexCode == "" {
+		resp.FailMsg("请输入指标code码", "请输入指标code码", c)
+		return
+	}
+	if req.Source == "" {
+		resp.FailMsg("请输入指标来源", "请输入指标来源", c)
+		return
+	}
+	list, err, errMsg := index_data_service.GetIndexFromJiaYue(req.IndexCode, req.Source)
+	if err != nil {
+		resp.FailMsg("查询失败", errMsg, c)
+		return
+	}
+	data := new(response.IndexResp)
+	data.IndexData = list
+	data.IndexCode = req.IndexCode
+	resp.OkData("操作成功", data, c)
+	return
+}

+ 5 - 0
core/run_server.go

@@ -18,6 +18,11 @@ func RunServe() {
 		//初始化redis
 		init_serve.RedisTool()
 	}
+
+	if global.CONFIG.OracleJY.Account != "" {
+		//初始化oracle
+		//	init_serve.OracleJy()
+	}
 	// 启动任务
 	init_serve.InitTask()
 

+ 2 - 0
global/global.go

@@ -1,6 +1,7 @@
 package global
 
 import (
+	"database/sql"
 	"eta/eta_bridge/config"
 	"eta/eta_bridge/utils"
 	"fmt"
@@ -21,6 +22,7 @@ var (
 	MYSQL_LOG     io.Writer
 	DEFAULT_MYSQL *gorm.DB      //默认数据库连接配置
 	Redis         *redis.Client //redis链接
+	OracleJy      *sql.DB       //嘉悦物产数据库连接
 
 	Rc *cache.Cache //redis缓存
 	Re error        //redis错误

+ 19 - 7
go.mod

@@ -11,6 +11,7 @@ require (
 	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/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
@@ -26,19 +27,24 @@ require (
 	github.com/KyleBanks/depth v1.2.1 // indirect
 	github.com/PuerkitoBio/purell v1.1.1 // indirect
 	github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
+	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/bytedance/sonic v1.9.1 // indirect
-	github.com/cespare/xxhash/v2 v2.1.2 // indirect
+	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	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-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/protobuf v1.5.3 // indirect
+	github.com/hashicorp/golang-lru v0.5.4 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.5 // indirect
@@ -51,12 +57,17 @@ require (
 	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.6 // indirect
 	github.com/mattn/go-isatty v0.0.19 // indirect
+	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	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/pkg/errors v0.9.1 // indirect
-	github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
+	github.com/prometheus/client_golang v1.16.0 // indirect
+	github.com/prometheus/client_model v0.3.0 // indirect
+	github.com/prometheus/common v0.42.0 // indirect
+	github.com/prometheus/procfs v0.10.1 // indirect
+	github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
 	github.com/spf13/afero v1.9.5 // indirect
 	github.com/spf13/cast v1.5.1 // indirect
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
@@ -65,11 +76,12 @@ require (
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 	github.com/ugorji/go/codec v1.2.11 // indirect
 	golang.org/x/arch v0.3.0 // indirect
-	golang.org/x/crypto v0.9.0 // indirect
-	golang.org/x/net v0.10.0 // indirect
-	golang.org/x/sys v0.8.0 // indirect
-	golang.org/x/text v0.11.0 // indirect
-	golang.org/x/tools v0.7.0 // indirect
+	golang.org/x/crypto v0.13.0 // indirect
+	golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
+	golang.org/x/net v0.15.0 // indirect
+	golang.org/x/sys v0.12.0 // indirect
+	golang.org/x/text v0.13.0 // indirect
+	golang.org/x/tools v0.13.0 // indirect
 	google.golang.org/protobuf v1.30.0 // indirect
 	gopkg.in/ini.v1 v1.67.0 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect

+ 41 - 0
init_serve/oracle_jy.go

@@ -0,0 +1,41 @@
+package init_serve
+
+import (
+	"database/sql"
+	"eta/eta_bridge/global"
+	"fmt"
+	"github.com/godror/godror"
+	"time"
+)
+
+func OracleJy() {
+	conf := global.CONFIG.OracleJY
+	err := connOracle(conf.Account, conf.Password, conf.Conn)
+	if err != nil {
+		fmt.Println("oracle 数据库连接失败")
+		global.LOG.Info("oracle 数据库连接失败,Err: " + err.Error())
+		panic("oracle 数据库连接失败" + err.Error())
+	}
+}
+
+func connOracle(username, pwd, connectionStr string) (err error) {
+	var P godror.ConnectionParams
+	P.Username, P.Password = username, godror.NewPassword(pwd)
+	P.ConnectString = connectionStr
+	/*	P.SessionTimeout = 42 * time.Second
+		P.SetSessionParamOnInit("NLS_NUMERIC_CHARACTERS", ",.")
+		P.SetSessionParamOnInit("NLS_LANGUAGE", "FRENCH")*/
+	P.Timezone = time.Local
+	P.LibDir = "/home/soft/oracle/instantclient_21_11"
+	oracleJyDb := sql.OpenDB(godror.NewConnector(P))
+	err = oracleJyDb.Ping()
+	if err != nil {
+		global.LOG.Error("oracle 数据库连接失败,Err: ", err)
+		panic(err)
+	}
+	fmt.Print("连接成功")
+	global.LOG.Info("oracle 数据库连接成功")
+
+	global.OracleJy = oracleJyDb
+	return
+}

+ 1 - 0
init_serve/router.go

@@ -19,5 +19,6 @@ func InitRouter() (r *gin.Engine) {
 	rBase := r.Group("api/")
 	routers.InitAuth(rBase)
 	routers.InitEtaTrial(rBase)
+	routers.InitIndexData(rBase)
 	return
 }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 15 - 0
models/jiayue/dict.go


+ 6 - 0
models/request/index_data/jiayue_index.go

@@ -0,0 +1,6 @@
+package index_data
+
+type IndexReq struct {
+	IndexCode string
+	Source    string
+}

+ 8 - 0
models/response/index_data.go

@@ -0,0 +1,8 @@
+package response
+
+import "eta/eta_bridge/models/jiayue"
+
+type IndexResp struct {
+	IndexCode string             `json:"index_code"`
+	IndexData []jiayue.IndexData `json:"index_data"`
+}

+ 14 - 0
routers/index_data.go

@@ -0,0 +1,14 @@
+package routers
+
+import (
+	"eta/eta_bridge/controller/index_data"
+	"github.com/gin-gonic/gin"
+)
+
+// InitIndexData 获取指标信息
+func InitIndexData(r *gin.RouterGroup) {
+	control := new(index_data.JiaYueIndexController)
+	//group := r.Group("index_data/").Use(middleware.Token())
+	group := r.Group("index_data/")
+	group.POST("jiayue/index", control.GetData)
+}

+ 49 - 0
services/index_data/jiayue_platform.go

@@ -0,0 +1,49 @@
+package index_data
+
+import (
+	"errors"
+	"eta/eta_bridge/global"
+	"eta/eta_bridge/models/jiayue"
+	"fmt"
+)
+
+func GetIndexFromJiaYue(indexCode, source string) (list []jiayue.IndexData, err error, errMsg string) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("GetIndexFromJiaYue: " + errMsg)
+		}
+	}()
+	indexList, err := jiayue.GetDictIndex(indexCode, source)
+	if err != nil {
+		errMsg = fmt.Sprintf("嘉悦物产指标信息查询失败,Err: %s", err)
+		return
+	}
+	if len(indexList) <= 0 {
+		return
+	}
+	index := indexList[0]
+	//获取指标数据
+	if index.TableName == "" {
+		errMsg = "指标信息不全,指标数据对应的表名为空"
+		err = errors.New(errMsg)
+		return
+	}
+	if index.Id <= 0 {
+		errMsg = "指标信息不全,指标对应的序号为空"
+		err = errors.New(errMsg)
+		return
+	}
+	indexData, err := jiayue.GetDictData(index.TableName, index.Id)
+	if err != nil {
+		errMsg = fmt.Sprintf("嘉悦物产指标数据信息查询失败,Err: %s", err)
+		return
+	}
+	for _, v := range indexData {
+		tmp := jiayue.IndexData{
+			Val:      v.IndexValue,
+			DataTime: v.IndexDate,
+		}
+		list = append(list, tmp)
+	}
+	return
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio