Commit e02431c5 by mushishixian

数据库修复

parent d97e6e75
<component name="ProjectDictionaryState">
<dictionary name="HUNT">
<words>
<w>xorm</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -3,35 +3,35 @@ package config
import (
"github.com/ichunt2019/cfg/lib"
)
type BaseDatabase struct {
DataSourceName string
MaxIdleCons int
MaxOpenCons int
Prefix string
MaxIdleCons int
MaxOpenCons int
Prefix string
}
type GroupDatabase struct {
DataSourceName []string
MaxIdleCons int
MaxOpenCons int
Prefix string
MaxIdleCons int
MaxOpenCons int
Prefix string
}
//单数据库配置
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{
"micro": {
DataSourceName: lib.Instance("db").GetString("micro.data_source_name"),
Prefix: lib.Instance("db").GetString("micro.table_prefix"),
MaxIdleCons:lib.Instance("db").GetInt("micro.max_idle_conn"),
MaxOpenCons:lib.Instance("db").GetInt("micro.max_open_conn"),
Prefix: lib.Instance("db").GetString("micro.table_prefix"),
MaxIdleCons: lib.Instance("db").GetInt("micro.max_idle_conn"),
MaxOpenCons: lib.Instance("db").GetInt("micro.max_open_conn"),
},
"supplier": {
DataSourceName: lib.Instance("db").GetString("supplier.data_source_name"),
Prefix: lib.Instance("db").GetString("supplier.table_prefix"),
MaxIdleCons:lib.Instance("db").GetInt("supplier.max_idle_conn"),
MaxOpenCons:lib.Instance("db").GetInt("supplier.max_open_conn"),
Prefix: lib.Instance("db").GetString("supplier.table_prefix"),
MaxIdleCons: lib.Instance("db").GetInt("supplier.max_idle_conn"),
MaxOpenCons: lib.Instance("db").GetInt("supplier.max_open_conn"),
},
}
}
......@@ -39,13 +39,6 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
//主从mysql数据库配置
func BuildGroupDatabaseList() (DatabaseList map[string]GroupDatabase) {
return map[string]GroupDatabase{
"liexin": {
DataSourceName:lib.Instance("db").GetStringSlice("liexin.data_source_name"),
Prefix: lib.Instance("db").GetString("micro.table_prefix"),
MaxIdleCons:lib.Instance("db").GetInt("micro.max_idle_conn"),
MaxOpenCons:lib.Instance("db").GetInt("micro.max_open_conn"),
},
}
}
......@@ -3,12 +3,12 @@ package dao
import (
"github.com/go-redis/redis/v7"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"github.com/ichunt2019/cfg/lib"
"go-supplier-sync/app/common/config"
"time"
"xorm.io/xorm"
redispool "github.com/ichunt2019/go-redis-pool"
redisPool "github.com/ichunt2019/go-redis-pool"
"sync"
)
......@@ -20,7 +20,7 @@ var (
type dao struct {
db map[string]*xorm.Engine //非主从mysql数据库
dbGroup map[string]*xorm.EngineGroup //mysql主从
redisGroup map[string]*redispool.Pool
redisGroup map[string]*redisPool.Pool
}
//获取db实例
......@@ -34,7 +34,7 @@ func (self *dao) GetDbGroup(databases string) *xorm.EngineGroup {
}
//获取主从db实例
func (self *dao) GetRedisDbGroup(databases string) *redispool.Pool {
func (self *dao) GetRedisDbGroup(databases string) *redisPool.Pool {
return self.redisGroup[databases]
}
......@@ -80,7 +80,7 @@ func redisSetup(d *dao) *dao {
var err error
redisGroupList := config.BuildRedisGroupConfigs()
for redisServerName, redisInfo := range redisGroupList {
d.redisGroup[redisServerName], err = redispool.NewHA(&redispool.HAConfig{
d.redisGroup[redisServerName], err = redisPool.NewHA(&redisPool.HAConfig{
Master: redisInfo.MasterHost,
Slaves: redisInfo.SlaveHost,
Password: redisInfo.Password,
......@@ -110,7 +110,7 @@ func Init() {
once.Do(func() {
Dao.db = make(map[string]*xorm.Engine, 0)
Dao.dbGroup = make(map[string]*xorm.EngineGroup, 0)
Dao.redisGroup = make(map[string]*redispool.Pool, 0)
Dao.redisGroup = make(map[string]*redisPool.Pool, 0)
Dao = mysqlSetup(Dao)
Dao = redisSetup(Dao)
})
......
package dao
import (
"fmt"
"go-supplier-sync/app/model"
)
func AddSupplierSync() {
var supplierSync model.SupplierSync
Dao.GetDb("supplier").Table("supplier_sync").Where("id", 1).Get(&supplierSync)
fmt.Println(supplierSync)
}
package dao
func AddSync() {
}
\ No newline at end of file
package model
type SupplierSync struct {
Id int
SupplierId int
ErpSync int
ErpSupplierCode string
AddTime int
UpdateTime int
}
......@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"go-supplier-sync/app/dao"
)
type RecvPro struct {
......@@ -25,6 +26,7 @@ func init() {
func (t *RecvPro) Consumer(dataByte []byte) (err error) {
fmt.Println("开始")
dao.AddSupplierSync()
return nil
}
......
......@@ -3,6 +3,6 @@ package service
import "go-supplier-sync/app/dao"
func AddSync() {
dao.GetUser()
func AddSupplierSync() {
dao.AddSupplierSync()
}
......@@ -3,39 +3,20 @@ module go-supplier-sync
go 1.14
require (
github.com/Chronokeeper/anyxml v0.0.0-20160530174208-54457d8e98c6 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet v2.1.2+incompatible // indirect
github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4 // indirect
github.com/bndr/gotabulate v1.1.2 // indirect
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-redis/redis/v7 v7.4.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gorilla/sessions v1.2.1 // indirect
github.com/ichunt2019/cfg v0.0.0-20210225081543-828ee9831d70
github.com/ichunt2019/cfg v0.0.0-20210310074903-4b1bcab17717
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/go-redis-pool v0.0.0-20210305064829-86b9011c57f5
github.com/ichunt2019/ichunt-micro-registry v1.0.1
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/lib/pq v1.9.0 // indirect
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/prometheus/common v0.4.0
github.com/spf13/viper v1.7.1
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
github.com/tidwall/gjson v1.6.8 // indirect
github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
github.com/xormplus/xorm v0.0.0-20210107091022-175d736afaae // indirect
google.golang.org/grpc/examples v0.0.0-20210226164526-c949703b4b98 // indirect
gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
google.golang.org/protobuf v1.25.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/xorm v1.0.7
)
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
......@@ -2,9 +2,9 @@ package lib
import (
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"go-supplier-sync/app/common/config"
"github.com/ichunt2019/cfg/lib"
"go-supplier-sync/app/common/config"
"xorm.io/xorm"
)
var DatabaseConMap map[string]*xorm.Engine
......@@ -38,7 +38,3 @@ func Setup() error {
func Conn(conName string) *xorm.Engine {
return DatabaseConMap[conName]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment