Browse Source

任务 #6755 【Go查询】添加配置商品盘面信息获取方式:MySQL(原逻辑)、Redis(新实现);配置为从Redis获取时,不再需要配置MySQL连接参数

muchinfo 3 months ago
parent
commit
b19be16fd9
8 changed files with 233 additions and 158 deletions
  1. 13 1
      config/config.go
  2. 8 7
      config/config.xml
  3. 22 5
      controllers/quote/quote.go
  4. 4 3
      go.mod
  5. 8 6
      go.sum
  6. 11 9
      main.go
  7. 163 125
      models/quote.go
  8. 4 2
      mtpcache/goods.go

+ 13 - 1
config/config.go

@@ -56,6 +56,7 @@ type MongoDBConfig struct {
 }
 
 type MySQLConfig struct {
+	Enabled  int
 	Host     string
 	Port     int
 	DBName   string
@@ -352,6 +353,17 @@ func (c *ServiceConfig) Init(path string) error {
 	// MySQL配置
 	mysqlsettings := root.SelectElements("MySQLSetting")
 	for _, setting := range mysqlsettings {
+		// 启用标志
+		enabled := setting.SelectElement("Enabled")
+		if enabled == nil {
+			return errors.New("read mysql enabled failed")
+		}
+		ret, err := strconv.ParseUint(enabled.SelectAttrValue("value", "0"), 10, 32)
+		if err != nil {
+			return errors.New("read mysql enabled failed")
+		}
+		SerCfg.MySQLCfg.Enabled = int(ret)
+
 		// 主机地址
 		host := setting.SelectElement("Host")
 		if host == nil {
@@ -364,7 +376,7 @@ func (c *ServiceConfig) Init(path string) error {
 		if port == nil {
 			return errors.New("read mysql port failed")
 		}
-		ret, err := strconv.ParseUint(port.SelectAttrValue("value", "3306"), 10, 32)
+		ret, err = strconv.ParseUint(port.SelectAttrValue("value", "3306"), 10, 32)
 		if err != nil {
 			return errors.New("read mysql port failed")
 		}

+ 8 - 7
config/config.xml

@@ -16,11 +16,11 @@
     <DbName value="orcl"/>
     <DbPort value="1521"/>
     <!-- DbUser DbPwd 支持明文密文 -->
-    <DbUser value="mtp2_test136"/>
+    <DbUser value="mtp2_JTB"/>
     <DbPwd value="muchinfo"/>
   </DbSetting>
   <RedisSetting>
-    <Address value="192.168.31.136"/>
+    <Address value="192.168.31.169"/>
     <Port value="5007"/>
     <Timeout value="3"/>
     <ConnNum value="1"/>
@@ -30,11 +30,11 @@
   </RedisSetting>
   <MqSetting>
     <!-- Url 支持明文密文 -->
-    <Url value="amqp://guest:guest@192.168.31.136:5020/test"/>
+    <Url value="amqp://guest:guest@192.168.31.169:5020/test"/>
     <Exchange value="entry"/>
   </MqSetting>
   <MongoDBSetting>
-    <HostName value="192.168.31.136"/>
+    <HostName value="192.168.31.169"/>
     <Port value="5025"/>
     <DBName value="HistoryQuote"/>
     <!-- Username Password 支持明文密文 -->
@@ -42,11 +42,12 @@
     <Password value="123456"/>
   </MongoDBSetting>
   <MySQLSetting>
+    <Enabled value="0"/>
     <Host value="192.168.30.72"/>
     <Port value="3306"/>
-    <DBName value="historyquote_test136"/>
+    <DBName value="historyquote_test169"/>
     <!-- Username Password 支持明文密文 -->
-    <Username value="quote_test136"/>
+    <Username value="quote_test169"/>
     <Password value="123456"/>
   </MySQLSetting>
 <Tencent>
@@ -66,7 +67,7 @@
     <AppId value="028288682"/>
     <PrivateKey value="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCl+o3JA7u724TabBVR+cBuxbIaNOlW54fFDLqE6Kxm0Ym/2y3yZDVkcY9WTxXnvb1wRAzpyIneatZQ6hgqCVRsMZn3MZ9/6qpPApKufEN5TilCZ8+Og++fOLPODNQFDLfWHMKjZxmqWK8vOtEmneWn/JFwy1he2EBmXOYqyzu5FIKutOgLeEHoocdaNwtiaBhCulxEonze818q58TxLe1kcOBf9Dmk1BUOqDYxAY5FbqnDDVTKVTL9G8rw9XUJ0NO0hoqKKAciMgcV9epEN0/AQuir3rBrh1vXCf6mwVfYKFpqw+LJLv4WkOjai21xuiMYdU7Vibv95h862Aj8ovAfAgMBAAECggEBAIxrdgqrGueqpzH3IO5ygkf0/2HGg+afCLE/vIj3I+v0uDpVXwDjoHwyytZ1IA4n6x4QpHAg1esSrfBUrE7cB81lBWIpXExnJuCjR59Qx/DXnHZuxx1GJ7Kn0Q6wsar4AIunV0/QyNjiIIuvkgS+ru248v7fOgs7nvg6/gsUV5mTDppV6kf4lI14Mvpa7MIwKK2bB1zzLsWA7X9IuBS/QNxv+rRykc/uhZofDhWvaXbwGKxFf6unY2HwC3IFQONOdD6LlXyMdNT2pjMdPGdVu79eOC6wn2HBiIp7lXs08NqiL3oJ9Hh8+lqO0HVz5OMkpdaofXa7wDvZtdxGwsAlBokCgYEA5tgZWo/zK/u9GHCZrtwk9mP057BFy/83tl/c8ZmUT1CkyGx3/czVCvPZSjl6FBYWw6Bj1opwIBcQis83Kd7FHbVMgNDgg7Tyew+OAMUnM8GmWFHNQ/jA8Xe251yFOmoPwT/2MbGgwqmJjEtxD0zKPo8OVaK1odPZXN1g+KAjXjUCgYEAuBDkgrhpd8NrEa5OrxtiSipdgj8bmC7ET9xJVzFtoHFYybFCexQUA0z2NouA0GGw8qahOCx/a/CIP/hL1X3tZFUwuGjq3iSxBwhaM4aUPmDY1ratCCIxEQsl5eosGi54ltIVDE1yAgut3wMFP0YKM5ht/uBssPHrP7/gqdsGL4MCgYBcB0S8TO0F2Ns+9gzeoBcAP0MwZp68v+dnBnqfurlckWrQGCYSAWnhbutuYtGfVlsG7FdA/XnL4UYQAKIeSBhPSqrQI/WNrEKK+t2CwxZo1MfLJ/lsIqxQ14gMXl8itYvIYAZ3MzhCwrH6Q000a0mpfQCa9T3x4PIjyoHRPI49DQKBgBtZlzq9QB6lkOE9rz9hqEcw6FgUHHuOZ2keaF9mXs26SeEeT6yOHTMoWmVccTWFbo9/pvD726skQHqQ4GPGpGGGLwkXvd5oQU20NgL1+k0SguXUmv1cZ0ILEASLuSXixdRTPwFm+IvJRHqgrkTqmVV1TtLSchQQvk3oqu9SNicVAoGAYWga1T1D8MW0v7q2d05hJ3JqgHbAYZmKVxlR2Moh33fzV8CmusY3FhnbPQi8Lorj/CexjfXgvG+rZfa713qtJYLHWmJ7hQKwBQH9J0QPO3ffQyFAM1RjJyIvB9BPt8zN2QbujR4O6wXFee1zjKYgnuBAt7dBmE3O3nNdXAMa1g4="/>
     <NotifyUrl value="http://218.17.158.45:15105/api/Asign/HandleASignCompleted"/>
-    <OpenApiUrl value="http://192.168.31.136:5015/mtp2-onlineopen"/>
+    <OpenApiUrl value="http://192.168.31.169:5015/mtp2-onlineopen"/>
     <Account value="12345678"/>
   </Asign>
   <TencentCloud>

+ 22 - 5
controllers/quote/quote.go

@@ -1,6 +1,7 @@
 package quote
 
 import (
+	"mtp2_if/config"
 	"mtp2_if/global/app"
 	"mtp2_if/global/e"
 	"mtp2_if/logger"
@@ -168,12 +169,28 @@ func QueryQuoteDay(c *gin.Context) {
 	}
 
 	rsp := make([]QueryQuoteDayRsp, 0)
-	quoteDays, err := models.GetQuoteDays(req.GoodsCodes)
-	if err != nil {
-		logger.GetLogger().Errorf("QueryQuoteDay failed: %s", err.Error())
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-		return
+	quoteDays := make([]models.Quoteday, 0)
+
+	// 判断是否启用 MySQL
+	if config.SerCfg.MySQLCfg.Enabled == 1 {
+		var err error
+		quoteDays, err = models.GetQuoteDays(req.GoodsCodes)
+		if err != nil {
+			logger.GetLogger().Errorf("QueryQuoteDay failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
+	} else {
+		// 从 Redis 获取盘面
+		var err error
+		quoteDays, err = models.QueryRedisQuoteDays(req.GoodsCodes)
+		if err != nil {
+			logger.GetLogger().Errorf("QueryQuoteDay failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
 	}
+
 	for _, v := range quoteDays {
 		// 获取对应的商品信息
 		goods, bFind := mtpcache.GetGoods(v.Goodscode)

+ 4 - 3
go.mod

@@ -59,8 +59,9 @@ require (
 
 require (
 	github.com/bwmarrin/snowflake v0.3.0
-	github.com/bytedance/sonic v1.12.7
+	github.com/bytedance/sonic v1.14.0
 	github.com/gin-contrib/gzip v1.2.0
+	github.com/go-viper/mapstructure/v2 v2.4.0
 	github.com/swaggo/files v1.0.1
 	github.com/swaggo/gin-swagger v1.6.0
 	github.com/swaggo/swag v1.16.2
@@ -73,8 +74,8 @@ 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/bytedance/sonic/loader v0.2.2 // indirect
-	github.com/cloudwego/base64x v0.1.4 // indirect
+	github.com/bytedance/sonic/loader v0.3.0 // indirect
+	github.com/cloudwego/base64x v0.1.5 // indirect
 	github.com/fsnotify/fsnotify v1.4.7 // indirect
 	github.com/gabriel-vasile/mimetype v1.4.8 // indirect
 	github.com/gin-contrib/sse v1.0.0 // indirect

+ 8 - 6
go.sum

@@ -24,15 +24,15 @@ github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c
 github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
 github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
 github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
-github.com/bytedance/sonic v1.12.7 h1:CQU8pxOy9HToxhndH0Kx/S1qU/CuS9GnKYrGioDcU1Q=
-github.com/bytedance/sonic v1.12.7/go.mod h1:tnbal4mxOMju17EGfknm2XyYcpyCnIROYOEYuemj13I=
+github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
+github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
 github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
-github.com/bytedance/sonic/loader v0.2.2 h1:jxAJuN9fOot/cyz5Q6dUuMJF5OqQ6+5GfA8FjjQ0R4o=
-github.com/bytedance/sonic/loader v0.2.2/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
+github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
+github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
 github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
 github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
-github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
-github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
+github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
+github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
 github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -74,6 +74,8 @@ github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e
 github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
+github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
 github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
 github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=

+ 11 - 9
main.go

@@ -3,7 +3,6 @@ package main
 import (
 	"context"
 	"mtp2_if/controllers/other"
-	"mtp2_if/models"
 	"mtp2_if/utils"
 	"net/http"
 	"os"
@@ -88,14 +87,17 @@ func main() {
 	}
 
 	if cmd.IsInit("mysql") {
-		// 初始化MySQL引擎
-		err = db.InitMySQLDbEngine()
-		if err != nil {
-			logger.GetLogger().Errorf("init mysql engine failed:%v", err.Error())
-			return
+		// 判断是否启用MySQL
+		if config.SerCfg.MySQLCfg.Enabled == 1 {
+			// 初始化MySQL引擎
+			err = db.InitMySQLDbEngine()
+			if err != nil {
+				logger.GetLogger().Errorf("init mysql engine failed:%v", err.Error())
+				return
+			}
+			go db.StartCheckConnection(1)
+			defer db.CloseMySQL()
 		}
-		go db.StartCheckConnection(1)
-		defer db.CloseMySQL()
 	}
 
 	if cmd.IsInit("redis") {
@@ -133,7 +135,7 @@ func main() {
 	}
 
 	// 启动定时同步盘面Timer
-	models.StartSyncRedisQuoteDay()
+	// models.StartSyncRedisQuoteDay()
 
 	// 设置超时
 	timeout := 15 * time.Second

+ 163 - 125
models/quote.go

@@ -11,6 +11,7 @@ import (
 	"strings"
 	"time"
 
+	"github.com/go-viper/mapstructure/v2"
 	"gopkg.in/mgo.v2/bson"
 )
 
@@ -84,130 +85,130 @@ type TikData struct {
 
 // Quoteday 行情盘面
 type Quoteday struct {
-	Id                   int64  `xorm:"pk autoincr BIGINT(20)"`
-	Exchangedate         int64  `xorm:"not null BIGINT(20)"`           // 交易日
-	Goodscode            string `xorm:"not null unique CHAR(10)"`      // 商品代码
-	Exchangecode         int    `xorm:"INT(11)"`                       // 交易所代码
-	Preclose             int64  `xorm:"default 0 BIGINT(20)"`          // 昨收
-	Opentime             int64  `xorm:"BIGINT(20)"`                    // 开盘时间
-	Opened               int64  `xorm:"not null default 0 BIGINT(20)"` // 开盘价
-	Highest              int64  `xorm:"not null default 0 BIGINT(20)"` // 最高价
-	Lowest               int64  `xorm:"not null default 0 BIGINT(20)"` // 最低价
-	Lasttime             string `xorm:"VARCHAR(20)"`                   // 行情时间(只有现价变化行情时间才变化)
-	Utclasttime          int64  `xorm:"not null BIGINT(20)"`           // utc的行情时间
-	Last                 int64  `xorm:"not null BIGINT(20)"`           // 最新价
-	Lastvolume           int64  `xorm:"default 0 BIGINT(20)"`          // 最新成交量
-	Lastturnover         int64  `xorm:"default 0 BIGINT(20)"`          // 最新成交金额
-	Totalbidvolume       int64  `xorm:"default 0 BIGINT(20)"`          // 外盘
-	Totalaskvolume       int64  `xorm:"default 0 BIGINT(20)"`          // 内盘
-	Totalvolume          int64  `xorm:"default 0 BIGINT(20)"`          // 总量
-	Totalturnover        int64  `xorm:"default 0 BIGINT(20)"`          // 总金额
-	Bid                  int64  `xorm:"default 0 BIGINT(20)"`          // 买1
-	Bid2                 int64  `xorm:"default 0 BIGINT(20)"`          // 买2
-	Bid3                 int64  `xorm:"default 0 BIGINT(20)"`          // 买3
-	Bid4                 int64  `xorm:"default 0 BIGINT(20)"`          // 买4
-	Bid5                 int64  `xorm:"default 0 BIGINT(20)"`          // 买5
-	Bidvolume            int64  `xorm:"default 0 BIGINT(20)"`          // 买量1
-	Bidvolume2           int64  `xorm:"default 0 BIGINT(20)"`          // 买量2
-	Bidvolume3           int64  `xorm:"default 0 BIGINT(20)"`          // 买量3
-	Bidvolume4           int64  `xorm:"default 0 BIGINT(20)"`          // 买量4
-	Bidvolume5           int64  `xorm:"default 0 BIGINT(20)"`          // 买量5
-	Ask                  int64  `xorm:"default 0 BIGINT(20)"`          // 卖1
-	Ask2                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖2
-	Ask3                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖3
-	Ask4                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖4
-	Ask5                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖5
-	Askvolume            int64  `xorm:"default 0 BIGINT(20)"`          // 卖量1
-	Askvolume2           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量2
-	Askvolume3           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量3
-	Askvolume4           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量4
-	Askvolume5           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量5
-	Presettle            int64  `xorm:"default 0 BIGINT(20)"`          // 昨结价
-	Settle               int64  `xorm:"default 0 BIGINT(20)"`          // 结算价
-	Preholdvolume        int64  `xorm:"default 0 BIGINT(20)"`          // 昨持仓
-	Holdvolume           int64  `xorm:"default 0 BIGINT(20)"`          // 持仓
-	Averageprice         int64  `xorm:"default 0 BIGINT(20)"`          // 均价
-	Orderid              int64  `xorm:"default 0 BIGINT(20)"`          // 序号
-	Limitup              int64  `xorm:"default 0 BIGINT(20)"`          // 涨停价
-	Limitdown            int64  `xorm:"default 0 BIGINT(20)"`          // 跌停价
-	Inventory            int64  `xorm:"default 0 BIGINT(20)"`          // 库存
-	Holdincrement        int64  `xorm:"default 0 BIGINT(20)"`          // 单笔持仓
-	Iscleared            int    `xorm:"INT(11)"`                       // 是否清盘标志
-	Issettled            int    `xorm:"INT(11)"`                       // 是否结算标志
-	Bidqueueinfo         string `xorm:"VARCHAR(2000)"`                 // 大利市买港股用
-	Askqueueinfo         string `xorm:"VARCHAR(2000)"`                 // 大利市卖港股用
-	Bidorderid           int64  `xorm:"BIGINT(20)"`                    // 买单号1
-	Bidorderid2          int64  `xorm:"BIGINT(20)"`                    // 买单号2
-	Bidorderid3          int64  `xorm:"BIGINT(20)"`                    // 买单号3
-	Bidorderid4          int64  `xorm:"BIGINT(20)"`                    // 买单号4
-	Bidorderid5          int64  `xorm:"BIGINT(20)"`                    // 买单号5
-	Askorderid           int64  `xorm:"BIGINT(20)"`                    // 卖单号1
-	Askorderid2          int64  `xorm:"BIGINT(20)"`                    // 卖单号2
-	Askorderid3          int64  `xorm:"BIGINT(20)"`                    // 卖单号3
-	Askorderid4          int64  `xorm:"BIGINT(20)"`                    // 卖单号4
-	Askorderid5          int64  `xorm:"BIGINT(20)"`                    // 卖单号5
-	Lastlot              int64  `xorm:"BIGINT(20)"`                    // 最新成交手数
-	Totallot             int64  `xorm:"BIGINT(20)"`                    // 总手数
-	Strikeprice          int64  `xorm:"BIGINT(20)"`                    // 发行价
-	Cleartime            int64  `xorm:"BIGINT(20)"`                    // 清盘时间
-	Calloptionpremiums   int64  `xorm:"default 0 BIGINT(20)"`          // 认购期权1
-	Calloptionpremiums2  int64  `xorm:"default 0 BIGINT(20)"`          // 认购期权2
-	Calloptionpremiums3  int64  `xorm:"default 0 BIGINT(20)"`          // 认购期权3
-	Calloptionpremiums4  int64  `xorm:"default 0 BIGINT(20)"`          // 认购期权4
-	Calloptionpremiums5  int64  `xorm:"default 0 BIGINT(20)"`          // 认购期权5
-	Putoptionpremiums    int64  `xorm:"default 0 BIGINT(20)"`          // 认沽期权1
-	Putoptionpremiums2   int64  `xorm:"default 0 BIGINT(20)"`          // 认沽期权2
-	Putoptionpremiums3   int64  `xorm:"default 0 BIGINT(20)"`          // 认沽期权3
-	Putoptionpremiums4   int64  `xorm:"default 0 BIGINT(20)"`          // 认沽期权4
-	Putoptionpremiums5   int64  `xorm:"default 0 BIGINT(20)"`          // 认沽期权5
-	Nontotalvolume       int64  `xorm:"default 0 BIGINT(20)"`          // 非交易总量
-	Nontotalholdervolume int64  `xorm:"default 0 BIGINT(20)"`          // 非交易持仓量
-	Nontotalturnover     int64  `xorm:"default 0 BIGINT(20)"`          // 非交易总金额
-	Nontotallot          int64  `xorm:"default 0 BIGINT(20)"`          // 非交易总手数
-	Publictradetype      string `xorm:"VARCHAR(2)"`                    // 公共交易标志类型 港股专用
-	Iep                  int64  `xorm:"default 0 BIGINT(20)"`          // 平衡价 港股专用
-	Iev                  int64  `xorm:"default 0 BIGINT(20)"`          // 平衡量 港股专用
-	Grepmarketprice      int64  `xorm:"default 0 BIGINT(20)"`          // 暗盘价 港股专用
-	Bid6                 int64  `xorm:"default 0 BIGINT(20)"`          // 买6
-	Bid7                 int64  `xorm:"default 0 BIGINT(20)"`          // 买7
-	Bid8                 int64  `xorm:"default 0 BIGINT(20)"`          // 买8
-	Bid9                 int64  `xorm:"default 0 BIGINT(20)"`          // 买9
-	Bid10                int64  `xorm:"default 0 BIGINT(20)"`          // 买10
-	Bidvolume6           int64  `xorm:"default 0 BIGINT(20)"`          // 买量6
-	Bidvolume7           int64  `xorm:"default 0 BIGINT(20)"`          // 买量7
-	Bidvolume8           int64  `xorm:"default 0 BIGINT(20)"`          // 买量8
-	Bidvolume9           int64  `xorm:"default 0 BIGINT(20)"`          // 买量9
-	Bidvolume10          int64  `xorm:"default 0 BIGINT(20)"`          // 买量10
-	Ask6                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖6
-	Ask7                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖7
-	Ask8                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖8
-	Ask9                 int64  `xorm:"default 0 BIGINT(20)"`          // 卖9
-	Ask10                int64  `xorm:"default 0 BIGINT(20)"`          // 卖10
-	Askvolume6           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量6
-	Askvolume7           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量7
-	Askvolume8           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量8
-	Askvolume9           int64  `xorm:"default 0 BIGINT(20)"`          // 卖量9
-	Askvolume10          int64  `xorm:"default 0 BIGINT(20)"`          // 卖量10
-	Bidordervolume       int64  `xorm:"default 0 BIGINT(20)"`          // 买单量1
-	Bidordervolume2      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量2
-	Bidordervolume3      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量3
-	Bidordervolume4      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量4
-	Bidordervolume5      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量5
-	Bidordervolume6      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量6
-	Bidordervolume7      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量7
-	Bidordervolume8      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量8
-	Bidordervolume9      int64  `xorm:"default 0 BIGINT(20)"`          // 买单量9
-	Bidordervolume10     int64  `xorm:"default 0 BIGINT(20)"`          // 买单量10
-	Askordervolume       int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量1
-	Askordervolume2      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量2
-	Askordervolume3      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量3
-	Askordervolume4      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量4
-	Askordervolume5      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量5
-	Askordervolume6      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量6
-	Askordervolume7      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量7
-	Askordervolume8      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量8
-	Askordervolume9      int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量9
-	Askordervolume10     int64  `xorm:"default 0 BIGINT(20)"`          // 卖单量10
+	Id                   int64  `mapstructure:"" xorm:"pk autoincr BIGINT(20)"`
+	Exchangedate         int64  `mapstructure:"ExchangeDate" xorm:"not null BIGINT(20)"`          // 交易日
+	Goodscode            string `mapstructure:"GoodsCode" xorm:"not null unique CHAR(10)"`        // 商品代码
+	Exchangecode         int    `mapstructure:"ExchangeCode" xorm:"INT(11)"`                      // 交易所代码
+	Preclose             int64  `mapstructure:"Preclose" xorm:"default 0 BIGINT(20)"`             // 昨收
+	Opentime             int64  `mapstructure:"Opentime" xorm:"BIGINT(20)"`                       // 开盘时间
+	Opened               int64  `mapstructure:"Opened" xorm:"not null default 0 BIGINT(20)"`      // 开盘价
+	Highest              int64  `mapstructure:"Highest" xorm:"not null default 0 BIGINT(20)"`     // 最高价
+	Lowest               int64  `mapstructure:"Lowest" xorm:"not null default 0 BIGINT(20)"`      // 最低价
+	Lasttime             string `mapstructure:"Lasttime" xorm:"VARCHAR(20)"`                      // 行情时间(只有现价变化行情时间才变化)
+	Utclasttime          int64  `mapstructure:"Utclasttime" xorm:"not null BIGINT(20)"`           // utc的行情时间
+	Last                 int64  `mapstructure:"Last" xorm:"not null BIGINT(20)"`                  // 最新价
+	Lastvolume           int64  `mapstructure:"Lastvolume" xorm:"default 0 BIGINT(20)"`           // 最新成交量
+	Lastturnover         int64  `mapstructure:"Lastturnover" xorm:"default 0 BIGINT(20)"`         // 最新成交金额
+	Totalbidvolume       int64  `mapstructure:"Totalbidvolume" xorm:"default 0 BIGINT(20)"`       // 外盘
+	Totalaskvolume       int64  `mapstructure:"Totalaskvolume" xorm:"default 0 BIGINT(20)"`       // 内盘
+	Totalvolume          int64  `mapstructure:"Totalvolume" xorm:"default 0 BIGINT(20)"`          // 总量
+	Totalturnover        int64  `mapstructure:"Totalturnover" xorm:"default 0 BIGINT(20)"`        // 总金额
+	Bid                  int64  `mapstructure:"Bid" xorm:"default 0 BIGINT(20)"`                  // 买1
+	Bid2                 int64  `mapstructure:"Bid2" xorm:"default 0 BIGINT(20)"`                 // 买2
+	Bid3                 int64  `mapstructure:"Bid3" xorm:"default 0 BIGINT(20)"`                 // 买3
+	Bid4                 int64  `mapstructure:"Bid4" xorm:"default 0 BIGINT(20)"`                 // 买4
+	Bid5                 int64  `mapstructure:"Bid5" xorm:"default 0 BIGINT(20)"`                 // 买5
+	Bidvolume            int64  `mapstructure:"Bidvolume" xorm:"default 0 BIGINT(20)"`            // 买量1
+	Bidvolume2           int64  `mapstructure:"Bidvolume2" xorm:"default 0 BIGINT(20)"`           // 买量2
+	Bidvolume3           int64  `mapstructure:"Bidvolume3" xorm:"default 0 BIGINT(20)"`           // 买量3
+	Bidvolume4           int64  `mapstructure:"Bidvolume4" xorm:"default 0 BIGINT(20)"`           // 买量4
+	Bidvolume5           int64  `mapstructure:"Bidvolume5" xorm:"default 0 BIGINT(20)"`           // 买量5
+	Ask                  int64  `mapstructure:"Ask" xorm:"default 0 BIGINT(20)"`                  // 卖1
+	Ask2                 int64  `mapstructure:"Ask2" xorm:"default 0 BIGINT(20)"`                 // 卖2
+	Ask3                 int64  `mapstructure:"Ask3" xorm:"default 0 BIGINT(20)"`                 // 卖3
+	Ask4                 int64  `mapstructure:"Ask4" xorm:"default 0 BIGINT(20)"`                 // 卖4
+	Ask5                 int64  `mapstructure:"Ask5" xorm:"default 0 BIGINT(20)"`                 // 卖5
+	Askvolume            int64  `mapstructure:"Askvolume" xorm:"default 0 BIGINT(20)"`            // 卖量1
+	Askvolume2           int64  `mapstructure:"Askvolume2" xorm:"default 0 BIGINT(20)"`           // 卖量2
+	Askvolume3           int64  `mapstructure:"Askvolume3" xorm:"default 0 BIGINT(20)"`           // 卖量3
+	Askvolume4           int64  `mapstructure:"Askvolume4" xorm:"default 0 BIGINT(20)"`           // 卖量4
+	Askvolume5           int64  `mapstructure:"Askvolume5" xorm:"default 0 BIGINT(20)"`           // 卖量5
+	Presettle            int64  `mapstructure:"Presettle" xorm:"default 0 BIGINT(20)"`            // 昨结价
+	Settle               int64  `mapstructure:"Settle" xorm:"default 0 BIGINT(20)"`               // 结算价
+	Preholdvolume        int64  `mapstructure:"Preholdvolume" xorm:"default 0 BIGINT(20)"`        // 昨持仓
+	Holdvolume           int64  `mapstructure:"Holdvolume" xorm:"default 0 BIGINT(20)"`           // 持仓
+	Averageprice         int64  `mapstructure:"Averageprice" xorm:"default 0 BIGINT(20)"`         // 均价
+	Orderid              int64  `mapstructure:"Orderid" xorm:"default 0 BIGINT(20)"`              // 序号
+	Limitup              int64  `mapstructure:"Limitup" xorm:"default 0 BIGINT(20)"`              // 涨停价
+	Limitdown            int64  `mapstructure:"Limitdown" xorm:"default 0 BIGINT(20)"`            // 跌停价
+	Inventory            int64  `mapstructure:"Inventory" xorm:"default 0 BIGINT(20)"`            // 库存
+	Holdincrement        int64  `mapstructure:"Holdincrement" xorm:"default 0 BIGINT(20)"`        // 单笔持仓
+	Iscleared            int    `mapstructure:"Iscleared" xorm:"INT(11)"`                         // 是否清盘标志
+	Issettled            int    `mapstructure:"Issettled" xorm:"INT(11)"`                         // 是否结算标志
+	Bidqueueinfo         string `mapstructure:"Bidqueueinfo" xorm:"VARCHAR(2000)"`                // 大利市买港股用
+	Askqueueinfo         string `mapstructure:"Askqueueinfo" xorm:"VARCHAR(2000)"`                // 大利市卖港股用
+	Bidorderid           int64  `mapstructure:"Bidorderid" xorm:"BIGINT(20)"`                     // 买单号1
+	Bidorderid2          int64  `mapstructure:"Bidorderid2" xorm:"BIGINT(20)"`                    // 买单号2
+	Bidorderid3          int64  `mapstructure:"Bidorderid3" xorm:"BIGINT(20)"`                    // 买单号3
+	Bidorderid4          int64  `mapstructure:"Bidorderid4" xorm:"BIGINT(20)"`                    // 买单号4
+	Bidorderid5          int64  `mapstructure:"Bidorderid5" xorm:"BIGINT(20)"`                    // 买单号5
+	Askorderid           int64  `mapstructure:"Askorderid" xorm:"BIGINT(20)"`                     // 卖单号1
+	Askorderid2          int64  `mapstructure:"Askorderid2" xorm:"BIGINT(20)"`                    // 卖单号2
+	Askorderid3          int64  `mapstructure:"Askorderid3" xorm:"BIGINT(20)"`                    // 卖单号3
+	Askorderid4          int64  `mapstructure:"Askorderid4" xorm:"BIGINT(20)"`                    // 卖单号4
+	Askorderid5          int64  `mapstructure:"Askorderid5" xorm:"BIGINT(20)"`                    // 卖单号5
+	Lastlot              int64  `mapstructure:"Lastlot" xorm:"BIGINT(20)"`                        // 最新成交手数
+	Totallot             int64  `mapstructure:"Totallot" xorm:"BIGINT(20)"`                       // 总手数
+	Strikeprice          int64  `mapstructure:"Strikeprice" xorm:"BIGINT(20)"`                    // 发行价
+	Cleartime            int64  `mapstructure:"Cleartime" xorm:"BIGINT(20)"`                      // 清盘时间
+	Calloptionpremiums   int64  `mapstructure:"Calloptionpremiums" xorm:"default 0 BIGINT(20)"`   // 认购期权1
+	Calloptionpremiums2  int64  `mapstructure:"Calloptionpremiums2" xorm:"default 0 BIGINT(20)"`  // 认购期权2
+	Calloptionpremiums3  int64  `mapstructure:"Calloptionpremiums3" xorm:"default 0 BIGINT(20)"`  // 认购期权3
+	Calloptionpremiums4  int64  `mapstructure:"Calloptionpremiums4" xorm:"default 0 BIGINT(20)"`  // 认购期权4
+	Calloptionpremiums5  int64  `mapstructure:"Calloptionpremiums5" xorm:"default 0 BIGINT(20)"`  // 认购期权5
+	Putoptionpremiums    int64  `mapstructure:"Putoptionpremiums" xorm:"default 0 BIGINT(20)"`    // 认沽期权1
+	Putoptionpremiums2   int64  `mapstructure:"Putoptionpremiums2" xorm:"default 0 BIGINT(20)"`   // 认沽期权2
+	Putoptionpremiums3   int64  `mapstructure:"Putoptionpremiums3" xorm:"default 0 BIGINT(20)"`   // 认沽期权3
+	Putoptionpremiums4   int64  `mapstructure:"Putoptionpremiums4" xorm:"default 0 BIGINT(20)"`   // 认沽期权4
+	Putoptionpremiums5   int64  `mapstructure:"Putoptionpremiums5" xorm:"default 0 BIGINT(20)"`   // 认沽期权5
+	Nontotalvolume       int64  `mapstructure:"Nontotalvolume" xorm:"default 0 BIGINT(20)"`       // 非交易总量
+	Nontotalholdervolume int64  `mapstructure:"Nontotalholdervolume" xorm:"default 0 BIGINT(20)"` // 非交易持仓量
+	Nontotalturnover     int64  `mapstructure:"Nontotalturnover" xorm:"default 0 BIGINT(20)"`     // 非交易总金额
+	Nontotallot          int64  `mapstructure:"Nontotallot" xorm:"default 0 BIGINT(20)"`          // 非交易总手数
+	Publictradetype      string `mapstructure:"Publictradetype" xorm:"VARCHAR(2)"`                // 公共交易标志类型 港股专用
+	Iep                  int64  `mapstructure:"Iep" xorm:"default 0 BIGINT(20)"`                  // 平衡价 港股专用
+	Iev                  int64  `mapstructure:"Iev" xorm:"default 0 BIGINT(20)"`                  // 平衡量 港股专用
+	Grepmarketprice      int64  `mapstructure:"Grepmarketprice" xorm:"default 0 BIGINT(20)"`      // 暗盘价 港股专用
+	Bid6                 int64  `mapstructure:"Bid6" xorm:"default 0 BIGINT(20)"`                 // 买6
+	Bid7                 int64  `mapstructure:"Bid7" xorm:"default 0 BIGINT(20)"`                 // 买7
+	Bid8                 int64  `mapstructure:"Bid8" xorm:"default 0 BIGINT(20)"`                 // 买8
+	Bid9                 int64  `mapstructure:"Bid9" xorm:"default 0 BIGINT(20)"`                 // 买9
+	Bid10                int64  `mapstructure:"Bid10" xorm:"default 0 BIGINT(20)"`                // 买10
+	Bidvolume6           int64  `mapstructure:"Bidvolume6" xorm:"default 0 BIGINT(20)"`           // 买量6
+	Bidvolume7           int64  `mapstructure:"Bidvolume7" xorm:"default 0 BIGINT(20)"`           // 买量7
+	Bidvolume8           int64  `mapstructure:"Bidvolume8" xorm:"default 0 BIGINT(20)"`           // 买量8
+	Bidvolume9           int64  `mapstructure:"Bidvolume9" xorm:"default 0 BIGINT(20)"`           // 买量9
+	Bidvolume10          int64  `mapstructure:"Bidvolume10" xorm:"default 0 BIGINT(20)"`          // 买量10
+	Ask6                 int64  `mapstructure:"Ask6" xorm:"default 0 BIGINT(20)"`                 // 卖6
+	Ask7                 int64  `mapstructure:"Ask7" xorm:"default 0 BIGINT(20)"`                 // 卖7
+	Ask8                 int64  `mapstructure:"Ask8" xorm:"default 0 BIGINT(20)"`                 // 卖8
+	Ask9                 int64  `mapstructure:"Ask9" xorm:"default 0 BIGINT(20)"`                 // 卖9
+	Ask10                int64  `mapstructure:"Ask10" xorm:"default 0 BIGINT(20)"`                // 卖10
+	Askvolume6           int64  `mapstructure:"Askvolume6" xorm:"default 0 BIGINT(20)"`           // 卖量6
+	Askvolume7           int64  `mapstructure:"Askvolume7" xorm:"default 0 BIGINT(20)"`           // 卖量7
+	Askvolume8           int64  `mapstructure:"Askvolume8" xorm:"default 0 BIGINT(20)"`           // 卖量8
+	Askvolume9           int64  `mapstructure:"Askvolume9" xorm:"default 0 BIGINT(20)"`           // 卖量9
+	Askvolume10          int64  `mapstructure:"Askvolume10" xorm:"default 0 BIGINT(20)"`          // 卖量10
+	Bidordervolume       int64  `mapstructure:"Bidordervolume" xorm:"default 0 BIGINT(20)"`       // 买单量1
+	Bidordervolume2      int64  `mapstructure:"Bidordervolume2" xorm:"default 0 BIGINT(20)"`      // 买单量2
+	Bidordervolume3      int64  `mapstructure:"Bidordervolume3" xorm:"default 0 BIGINT(20)"`      // 买单量3
+	Bidordervolume4      int64  `mapstructure:"Bidordervolume4" xorm:"default 0 BIGINT(20)"`      // 买单量4
+	Bidordervolume5      int64  `mapstructure:"Bidordervolume5" xorm:"default 0 BIGINT(20)"`      // 买单量5
+	Bidordervolume6      int64  `mapstructure:"Bidordervolume6" xorm:"default 0 BIGINT(20)"`      // 买单量6
+	Bidordervolume7      int64  `mapstructure:"Bidordervolume7" xorm:"default 0 BIGINT(20)"`      // 买单量7
+	Bidordervolume8      int64  `mapstructure:"Bidordervolume8" xorm:"default 0 BIGINT(20)"`      // 买单量8
+	Bidordervolume9      int64  `mapstructure:"Bidordervolume9" xorm:"default 0 BIGINT(20)"`      // 买单量9
+	Bidordervolume10     int64  `mapstructure:"Bidordervolume10" xorm:"default 0 BIGINT(20)"`     // 买单量10
+	Askordervolume       int64  `mapstructure:"Askordervolume" xorm:"default 0 BIGINT(20)"`       // 卖单量1
+	Askordervolume2      int64  `mapstructure:"Askordervolume2" xorm:"default 0 BIGINT(20)"`      // 卖单量2
+	Askordervolume3      int64  `mapstructure:"Askordervolume3" xorm:"default 0 BIGINT(20)"`      // 卖单量3
+	Askordervolume4      int64  `mapstructure:"Askordervolume4" xorm:"default 0 BIGINT(20)"`      // 卖单量4
+	Askordervolume5      int64  `mapstructure:"Askordervolume5" xorm:"default 0 BIGINT(20)"`      // 卖单量5
+	Askordervolume6      int64  `mapstructure:"Askordervolume6" xorm:"default 0 BIGINT(20)"`      // 卖单量6
+	Askordervolume7      int64  `mapstructure:"Askordervolume7" xorm:"default 0 BIGINT(20)"`      // 卖单量7
+	Askordervolume8      int64  `mapstructure:"Askordervolume8" xorm:"default 0 BIGINT(20)"`      // 卖单量8
+	Askordervolume9      int64  `mapstructure:"Askordervolume9" xorm:"default 0 BIGINT(20)"`      // 卖单量9
+	Askordervolume10     int64  `mapstructure:"Askordervolume10" xorm:"default 0 BIGINT(20)"`     // 卖单量10
 }
 
 // TableName is Quoteday
@@ -375,7 +376,44 @@ func SetRedisQuoteDays() (err error) {
 	return
 }
 
-// GetRedisQuoteDays 从Redis读取盘面数据
+// QueryRedisQuoteDays 从Redis读取盘面数据
+func QueryRedisQuoteDays(goodsCodes string) (quoteDays []Quoteday, err error) {
+	exchangeCode := "250"
+	quoteDays = make([]Quoteday, 0)
+
+	redisCli := rediscli.GetRedisClient()
+	for _, goodsCode := range strings.Split(goodsCodes, ",") {
+		var m map[string]string
+		m, err = redisCli.HGetAll(fmt.Sprintf("QuoteDay:%s_%s", exchangeCode, goodsCode)).Result()
+		if err != nil {
+			return
+		}
+
+		if len(m) == 0 {
+			return
+		}
+
+		var quoteDay Quoteday
+		config := &mapstructure.DecoderConfig{
+			WeaklyTypedInput: true, // 启用弱类型转换,允许字符串自动转换为数字
+			Result:           &quoteDay,
+		}
+		decoder, err := mapstructure.NewDecoder(config)
+		if err != nil {
+			return quoteDays, err
+		}
+		err = decoder.Decode(m)
+		if err != nil {
+			return quoteDays, err
+		}
+
+		quoteDays = append(quoteDays, quoteDay)
+	}
+
+	return
+}
+
+// GetRedisQuoteDays 从Redis读取盘面数据(游客)
 func GetRedisQuoteDays(goodsCodes []string) (quoteDays []Quoteday, err error) {
 	redisCli := rediscli.GetRedisClient()
 	b, err := redisCli.Get("Tourist:QuoteDay").Bytes()

+ 4 - 2
mtpcache/goods.go

@@ -65,7 +65,8 @@ func init() {
 
 func loadData() {
 	m := Goods{}
-	if d, err := m.GetData(); err == nil {
+	d, err := m.GetData()
+	if err == nil {
 		for _, v := range d {
 			goodsCache.Add(v.Key(), 0, v)
 		}
@@ -153,7 +154,8 @@ func (r *Goods) GetData() ([]Goods, error) {
 func GetGoods(goodsCode string) (Goods, bool) {
 	// 缓存是用大写的goodscode, 查找也转成大写的来查找
 	goodsCode2 := strings.ToUpper(goodsCode)
-	if item, err := goodsCache.Value(goodsCode2); err == nil {
+	item, err := goodsCache.Value(goodsCode2)
+	if err == nil {
 		d := item.Data()
 		if v, ok := d.(Goods); ok {
 			return v, true