Commit 9d828ec5 by 孙龙

up

parent 8cc4bc42
...@@ -11,6 +11,7 @@ var ( ...@@ -11,6 +11,7 @@ var (
CmsDB *sqlx.DB CmsDB *sqlx.DB
CrmDB *sqlx.DB CrmDB *sqlx.DB
BomDB *sqlx.DB BomDB *sqlx.DB
OrderDB *sqlx.DB
) )
func Init(dns string) error { func Init(dns string) error {
...@@ -24,8 +25,8 @@ func Init(dns string) error { ...@@ -24,8 +25,8 @@ func Init(dns string) error {
if err != nil { if err != nil {
return err return err
} }
DB.SetMaxOpenConns(20) DB.SetMaxOpenConns(10)
DB.SetMaxIdleConns(10) DB.SetMaxIdleConns(5)
return nil return nil
} }
...@@ -40,8 +41,8 @@ func InitLabelDB(dns string) error{ ...@@ -40,8 +41,8 @@ func InitLabelDB(dns string) error{
if err != nil { if err != nil {
return err return err
} }
LabelDB.SetMaxOpenConns(20) LabelDB.SetMaxOpenConns(10)
LabelDB.SetMaxIdleConns(10) LabelDB.SetMaxIdleConns(5)
return nil return nil
} }
func InitBomDB(dns string) error{ func InitBomDB(dns string) error{
...@@ -55,8 +56,23 @@ func InitBomDB(dns string) error{ ...@@ -55,8 +56,23 @@ func InitBomDB(dns string) error{
if err != nil { if err != nil {
return err return err
} }
BomDB.SetMaxOpenConns(20) BomDB.SetMaxOpenConns(10)
BomDB.SetMaxIdleConns(10) BomDB.SetMaxIdleConns(5)
return nil
}
func InitOrderDB(dns string) error{
var err error
OrderDB, err = sqlx.Open("mysql", dns)
if err != nil {
return err
}
err = OrderDB.Ping()
if err != nil {
return err
}
OrderDB.SetMaxOpenConns(10)
OrderDB.SetMaxIdleConns(5)
return nil return nil
} }
func InitCmslDB(dns string) error{ func InitCmslDB(dns string) error{
...@@ -70,8 +86,8 @@ func InitCmslDB(dns string) error{ ...@@ -70,8 +86,8 @@ func InitCmslDB(dns string) error{
if err != nil { if err != nil {
return err return err
} }
CmsDB.SetMaxOpenConns(20) CmsDB.SetMaxOpenConns(10)
CmsDB.SetMaxIdleConns(10) CmsDB.SetMaxIdleConns(5)
return nil return nil
} }
...@@ -86,8 +102,8 @@ func InitCrmDB(dns string) error{ ...@@ -86,8 +102,8 @@ func InitCrmDB(dns string) error{
if err != nil { if err != nil {
return err return err
} }
CrmDB.SetMaxOpenConns(20) CrmDB.SetMaxOpenConns(10)
CrmDB.SetMaxIdleConns(10) CrmDB.SetMaxIdleConns(5)
return nil return nil
} }
...@@ -104,6 +120,8 @@ func CreateDB(action string,dns string) error{ ...@@ -104,6 +120,8 @@ func CreateDB(action string,dns string) error{
err = InitCrmDB(dns) err = InitCrmDB(dns)
case "BomDB": case "BomDB":
err = InitBomDB(dns) err = InitBomDB(dns)
case "OrderDb":
err = InitOrderDB(dns)
} }
return err return err
} }
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
func QueryUserOrder(user_id int) int { func QueryUserOrder(user_id int) int {
var count int var count int
err := db.DB.QueryRow("select count(*) from lie_order where user_id = ?", user_id).Scan(&count) err := db.OrderDB.QueryRow("select count(*) from lie_order where user_id = ?", user_id).Scan(&count)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
logger.Info("没有获取到用户订单,user_id:%d", user_id) logger.Info("没有获取到用户订单,user_id:%d", user_id)
...@@ -25,7 +25,7 @@ func QueryUserOrder(user_id int) int { ...@@ -25,7 +25,7 @@ func QueryUserOrder(user_id int) int {
func UpdateStatus(order_id int, status_extend int) (err error) { func UpdateStatus(order_id int, status_extend int) (err error) {
_, err1 := db.DB.Exec("update lie_order set status_extend = ?, wms_syn = ? where order_id = ?", status_extend, 1, order_id) _, err1 := db.OrderDB.Exec("update lie_order set status_extend = ?, wms_syn = ? where order_id = ?", status_extend, 1, order_id)
if err1 != nil { if err1 != nil {
logger.Fatal("数据库操作失败") logger.Fatal("数据库操作失败")
...@@ -89,7 +89,7 @@ func UpdateJingDiaoOrder() { ...@@ -89,7 +89,7 @@ func UpdateJingDiaoOrder() {
start_time := t.Unix() - 86400 start_time := t.Unix() - 86400
end_time := t.Unix() - 1 end_time := t.Unix() - 1
_, err := db.DB.Exec("update lie_order set status = ? where is_type = ? and status = ? and create_time between ? and ?", 8, 1, 4, start_time, end_time) _, err := db.OrderDB.Exec("update lie_order set status = ? where is_type = ? and status = ? and create_time between ? and ?", 8, 1, 4, start_time, end_time)
if err != nil { if err != nil {
logger.Fatal("更新昨天的竞调订单操作失败," + err.Error()) logger.Fatal("更新昨天的竞调订单操作失败," + err.Error())
......
...@@ -33,7 +33,7 @@ func AddLog() (err error) { ...@@ -33,7 +33,7 @@ func AddLog() (err error) {
func QueryRow() { func QueryRow() {
var actionLog ActionLog var actionLog ActionLog
err1 := db.DB.Get(&actionLog, "select * from lie_order_action_log where order_id = 3340") err1 := db.OrderDB.Get(&actionLog, "select * from lie_order_action_log where order_id = 3340")
if err1 == sql.ErrNoRows { if err1 == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1) log.Printf("not found data of the id:%d", 1)
...@@ -49,7 +49,7 @@ func QueryRow() { ...@@ -49,7 +49,7 @@ func QueryRow() {
// 多行查询 // 多行查询
func Query() { func Query() {
var actionLog2 []*ActionLog var actionLog2 []*ActionLog
err2 := db.DB.Select(&actionLog2, "select * from lie_order_action_log where order_id = 3340") err2 := db.OrderDB.Select(&actionLog2, "select * from lie_order_action_log where order_id = 3340")
if err2 == sql.ErrNoRows { if err2 == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1) log.Printf("not found data of the id:%d", 1)
...@@ -67,7 +67,7 @@ func Query() { ...@@ -67,7 +67,7 @@ func Query() {
func Insert(order_id int, operator_id int, operator_type int, event string) (err error) { func Insert(order_id int, operator_id int, operator_type int, event string) (err error) {
create_time := time.Now().Unix() create_time := time.Now().Unix()
_, err1 := db.DB.Exec("insert into lie_order_action_log (order_id, operator_id, operator_type, event, create_time) values (?, ?, ?, ?, ?)", order_id, operator_id, operator_type, event, create_time) _, err1 := db.OrderDB.Exec("insert into lie_order_action_log (order_id, operator_id, operator_type, event, create_time) values (?, ?, ?, ?, ?)", order_id, operator_id, operator_type, event, create_time)
if err1 != nil { if err1 != nil {
logger.Fatal("数据库操作失败") logger.Fatal("数据库操作失败")
......
...@@ -136,7 +136,7 @@ func getUserInfo(user_id int64) (userInfo *UserInfo,err error) { ...@@ -136,7 +136,7 @@ func getUserInfo(user_id int64) (userInfo *UserInfo,err error) {
func getOrderInfo(order_id int64) (orderItems *OrderItems,err error){ func getOrderInfo(order_id int64) (orderItems *OrderItems,err error){
orderItems = &OrderItems{} orderItems = &OrderItems{}
sql := `select sum(goods_number) as gnums from lie_order_items where order_id = ? and status = 1` sql := `select sum(goods_number) as gnums from lie_order_items where order_id = ? and status = 1`
err = db.DB.Get(orderItems,sql,order_id) err = db.OrderDB.Get(orderItems,sql,order_id)
if err != nil{ if err != nil{
return nil,err return nil,err
} }
......
...@@ -46,7 +46,7 @@ func BuildBomOrder(orderBomData *CreateOrderBomData) (err error){ ...@@ -46,7 +46,7 @@ func BuildBomOrder(orderBomData *CreateOrderBomData) (err error){
//查询订单相关信息 //查询订单相关信息
lieOrder := &LieOrderInfo{} lieOrder := &LieOrderInfo{}
getOrderSql := "select order_id,order_sn,order_amount,create_time,user_id from lie_order where order_id = ? " getOrderSql := "select order_id,order_sn,order_amount,create_time,user_id from lie_order where order_id = ? "
err = db.DB.Get(lieOrder,getOrderSql,order_id) err = db.OrderDB.Get(lieOrder,getOrderSql,order_id)
if err != nil{ if err != nil{
return returnError(fmt.Sprintf("没有找到相关平台订单信息 订单id: : %s",order_id)) return returnError(fmt.Sprintf("没有找到相关平台订单信息 订单id: : %s",order_id))
} }
......
...@@ -65,18 +65,18 @@ func InsertData(trackList OrderTrackList) error{ ...@@ -65,18 +65,18 @@ func InsertData(trackList OrderTrackList) error{
currency int64 currency int64
) )
//开启事务 //开启事务
tx, _ := db.DB.Beginx() tx, _ := db.OrderDB.Beginx()
for _,data := range trackList{ for _,data := range trackList{
orderItems := &OrderItems{} orderItems := &OrderItems{}
err = db.DB.Get(orderItems,"SELECT order_id,rec_id,goods_number,fqty FROM lie_order_items WHERE erp_rec_id = ?",data.ORDERENTRYID) err = db.OrderDB.Get(orderItems,"SELECT order_id,rec_id,goods_number,fqty FROM lie_order_items WHERE erp_rec_id = ?",data.ORDERENTRYID)
if err != nil{ if err != nil{
logger.Error("%s",fmt.Sprintf("没有找到该明细的信息 %s",data.ORDERENTRYID)) logger.Error("%s",fmt.Sprintf("没有找到该明细的信息 %s",data.ORDERENTRYID))
continue continue
} }
err = db.DB.Get(&currency,"SELECT currency FROM lie_order WHERE order_id = ?",orderItems.OrderId) err = db.OrderDB.Get(&currency,"SELECT currency FROM lie_order WHERE order_id = ?",orderItems.OrderId)
if err != nil{ if err != nil{
logger.Error("%s",fmt.Sprintf("没有找到订单信息 %d",orderItems.OrderId)) logger.Error("%s",fmt.Sprintf("没有找到订单信息 %d",orderItems.OrderId))
continue continue
......
...@@ -83,6 +83,7 @@ func main() { ...@@ -83,6 +83,7 @@ func main() {
//初始化db //初始化db
initDb("Init",util.Configs.Liexin_databases.Dns) initDb("Init",util.Configs.Liexin_databases.Dns)
initDb("OrderDb",util.Configs.Liexin_order_databases.Dns)
initDb("BomDB",util.Configs.Bom_databases.Dns) initDb("BomDB",util.Configs.Bom_databases.Dns)
......
...@@ -19,9 +19,20 @@ import ( ...@@ -19,9 +19,20 @@ import (
"math/rand" "math/rand"
) )
func initDb(dns string) (err error) { //func initDb(dns string) (err error) {
err = db.Init(dns) // err = db.Init(dns)
// if err != nil {
// return
// }
//
// return
//}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil { if err != nil {
fmt.Println(err)
panic(err)
return return
} }
...@@ -69,7 +80,8 @@ func main() { ...@@ -69,7 +80,8 @@ func main() {
logger.Init() logger.Init()
//初始化db //初始化db
initDb(util.Configs.Liexin_databases.Dns) initDb("Init",util.Configs.Liexin_databases.Dns)
initDb("OrderDb",util.Configs.Liexin_order_databases.Dns)
RedisConn = redis_connect(util.Configs) RedisConn = redis_connect(util.Configs)
......
...@@ -67,7 +67,7 @@ func GetOneOrderItem() OrderItems.OrderItems { ...@@ -67,7 +67,7 @@ func GetOneOrderItem() OrderItems.OrderItems {
var order_item OrderItems.OrderItems var order_item OrderItems.OrderItems
var field string = "rec_id,goods_id,supplier_id,brand_id,standard_brand_id,goods_sn,goods_name,sku_name,supplier_name,brand_name,standard_brand_name,goods_type," + var field string = "rec_id,goods_id,supplier_id,brand_id,standard_brand_id,goods_sn,goods_name,sku_name,supplier_name,brand_name,standard_brand_name,goods_type," +
"self_supplier_type,goods_number,goods_price,delivery_time,sale_type,ac_type,order_goods_type,buyer_id,batch" "self_supplier_type,goods_number,goods_price,delivery_time,sale_type,ac_type,order_goods_type,buyer_id,batch"
db.DB.Get(&order_item, "select "+field+" from lie_order_items as a join (select round( rand() * (select max(rec_id) from lie_order_items)) as brec_id) as b " + db.OrderDB.Get(&order_item, "select "+field+" from lie_order_items as a join (select round( rand() * (select max(rec_id) from lie_order_items)) as brec_id) as b " +
"on a.rec_id > b.brec_id and a.goods_price > 0.1 LIMIT 1") "on a.rec_id > b.brec_id and a.goods_price > 0.1 LIMIT 1")
return order_item return order_item
...@@ -76,12 +76,12 @@ func GetOneOrderItem() OrderItems.OrderItems { ...@@ -76,12 +76,12 @@ func GetOneOrderItem() OrderItems.OrderItems {
// 随机获取一条收货地址 // 随机获取一条收货地址
func GetOrderAddress() JingdiaoAddress.JingdiaoAddress { func GetOrderAddress() JingdiaoAddress.JingdiaoAddress {
var count int var count int
db.DB.QueryRow("select count(*) from lie_jingdiao_address").Scan(&count) db.OrderDB.QueryRow("select count(*) from lie_jingdiao_address").Scan(&count)
rand_num := RandInt(1, count + 1) // 从总数中取个随机数 rand_num := RandInt(1, count + 1) // 从总数中取个随机数
var address JingdiaoAddress.JingdiaoAddress var address JingdiaoAddress.JingdiaoAddress
db.DB.Get(&address, "select id, company, lianxiren, address, user_id, telphone from lie_jingdiao_address where id = ? and user_id != 0", rand_num) db.OrderDB.Get(&address, "select id, company, lianxiren, address, user_id, telphone from lie_jingdiao_address where id = ? and user_id != 0", rand_num)
if address.Id == 0 { if address.Id == 0 {
return GetOrderAddress() return GetOrderAddress()
...@@ -154,7 +154,7 @@ func GetOrderSn() string { ...@@ -154,7 +154,7 @@ func GetOrderSn() string {
var sn string = createOrderSn() var sn string = createOrderSn()
var order_id int var order_id int
db.DB.Get(&order_id, "select order_id from lie_order where order_sn = ?", sn) db.OrderDB.Get(&order_id, "select order_id from lie_order where order_sn = ?", sn)
if order_id != 0 { if order_id != 0 {
return GetOrderSn() return GetOrderSn()
......
...@@ -53,6 +53,7 @@ func main() { ...@@ -53,6 +53,7 @@ func main() {
//初始化db //初始化db
initDb("Init", util.Configs.Liexin_databases.Dns) initDb("Init", util.Configs.Liexin_databases.Dns)
initDb("InitCmsDB", util.Configs.Liexincms_databases.Dns) initDb("InitCmsDB", util.Configs.Liexincms_databases.Dns)
initDb("OrderDb",util.Configs.Liexin_order_databases.Dns)
if StartTime != "" && EndTime != "" { // 开始时间和结束时间都存在 if StartTime != "" && EndTime != "" { // 开始时间和结束时间都存在
forever := make(chan bool) forever := make(chan bool)
...@@ -166,7 +167,7 @@ func CreateOrder(create_time int64) { ...@@ -166,7 +167,7 @@ func CreateOrder(create_time int64) {
goods_data["buyer_id"] = order_item.BuyerId goods_data["buyer_id"] = order_item.BuyerId
goods_data["batch"] = order_item.Batch goods_data["batch"] = order_item.Batch
conn, err := db.DB.Begin() // 开启事务 conn, err := db.OrderDB.Begin() // 开启事务
if err != nil { if err != nil {
return return
} }
......
...@@ -78,6 +78,8 @@ func main(){ ...@@ -78,6 +78,8 @@ func main(){
//初始化db //初始化db
initDb("Init",util.Configs.Liexin_databases.Dns) initDb("Init",util.Configs.Liexin_databases.Dns)
initDb("OrderDb",util.Configs.Liexin_order_databases.Dns)
t := &RecvPro{} t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{ rabbitmq.Recv(rabbitmq.QueueExchange{
......
...@@ -86,6 +86,7 @@ func main() { ...@@ -86,6 +86,7 @@ func main() {
//初始化db //初始化db
initDb("Init",util.Configs.Liexin_databases.Dns) initDb("Init",util.Configs.Liexin_databases.Dns)
initDb("OrderDb",util.Configs.Liexin_order_databases.Dns)
//initDb("InitLabelDB",util.Configs.LiexinLabel_databases.Dns) //initDb("InitLabelDB",util.Configs.LiexinLabel_databases.Dns)
//initDb("InitCmsDB",util.Configs.Liexincms_databases.Dns) //initDb("InitCmsDB",util.Configs.Liexincms_databases.Dns)
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
//订制配置文件解析载体 //订制配置文件解析载体
type Config struct { type Config struct {
Liexin_databases *LiexinMysqlConfig Liexin_databases *LiexinMysqlConfig
Liexin_order_databases *LiexinOrderMysqlConfig
LiexinLabel_databases *LiexinLabelMysqlConfig LiexinLabel_databases *LiexinLabelMysqlConfig
Liexincms_databases *LiexinCmsMysqlConfig Liexincms_databases *LiexinCmsMysqlConfig
Liexincrm_databases *LiexinCrmMysqlConfig Liexincrm_databases *LiexinCrmMysqlConfig
...@@ -30,6 +31,10 @@ type LiexinMysqlConfig struct { ...@@ -30,6 +31,10 @@ type LiexinMysqlConfig struct {
Dns string `toml:"dns"` Dns string `toml:"dns"`
} }
type LiexinOrderMysqlConfig struct {
Dns string `toml:"dns"`
}
type LiexinLabelMysqlConfig struct { type LiexinLabelMysqlConfig struct {
Dns string `toml:"dns"` Dns string `toml:"dns"`
} }
......
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