Commit d0f9bd9e by Joneq

增加适配模型

parent 47c2cf62
......@@ -3,9 +3,11 @@ package main
import (
"context"
"flag"
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/service"
"strconv"
)
//当前静态算法内的pid和typeID
......@@ -23,12 +25,17 @@ func main() {
log.Init(&log.Config{Dir: "logs"})
defer log.Close()
log.Info("caipu-server start")
//声明service层
svc := service.New()
ctx := context.Background()
//调用会员服务
svc.GetCompanyCresitsList(ctx)
userdata,_ := svc.GetCompanyCresitsList(ctx)
for _,v :=range userdata{
fmt.Print(strconv.Atoi(v["create_time"].(string)))
}
}
......
[liexin_credit]
[Liexin_credit]
addr = "192.168.2.232:3306"
dsn = "liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
readDSN = ["liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"]
readDSN = ["liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8","liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8,utf8mb4"]
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "200ms"
execTimeout = "300ms"
tranTimeout = "400ms"
......@@ -2,16 +2,48 @@ package dao
import (
"context"
"fmt"
"github.com/bilibili/kratos/pkg/database/sql"
"github.com/pkg/errors"
"kaopu-server/internal/model"
)
//根据指针行获取所有的参数
func getAllParam(rows *sql.Rows)(res []map[string]interface{}, err error) {
cols,err := rows.Columns()
if err != nil{
fmt.Println("get columns fail,err:",err)
return
}
vals := make([][]byte, len(cols))
scans := make([]interface{},len(cols))
for i := range vals{
scans[i] = &vals[i]
}
for rows.Next(){
err = rows.Scan(scans...)
if err != nil{
fmt.Println("scan fail,err:",err)
return
}
row := make(map[string]interface{})
for k,v:=range vals{
key := cols[k]
row[key] =string(v)
}
res = append(res,row)
}
return
}
//列表方式获取会员信息
func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []*model.ComCredits, err error) {
func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []map[string]interface{}, err error) {
var (
rows *sql.Rows
)
if rows, err = d.db.Query(ctx, "SELECT * FROM lie_com_credits "); err != nil {
err = errors.WithStack(err)
......@@ -19,16 +51,11 @@ func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []*model.ComCredit
}
defer rows.Close()
for rows.Next() {
r := &model.ComCredits{}
if err = rows.Scan(&r.ComName, &r.ComOrganization); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
if err != nil{
fmt.Println("select fail,err:",err)
return
}
err = rows.Err()
return
return getAllParam(rows)
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ type Dao interface {
Ping(ctx context.Context) (err error)
GetUserInfoByUserId(ctx context.Context,user_id int64) (r *model.Users,err error)
GetUserList(ctx context.Context) (r []*model.Users,err error)
GetCompanyCresitsList(ctx context.Context) (r []*model.ComCredits,err error)
GetCompanyCresitsList(ctx context.Context) (r []map[string]interface{},err error)
}
// dao dao.
......
......@@ -60,11 +60,9 @@ func (s *Service) GetUserList(ctx context.Context) (res []*model.Users, err erro
//获取用户列表
func (s *Service) GetCompanyCresitsList(ctx context.Context) (res []*model.ComCredits, err error) {
func (s *Service) GetCompanyCresitsList(ctx context.Context) (res []map[string]interface{}, err error) {
//调用DB方法,获取会员数据
res, _ = s.dao.GetCompanyCresitsList(ctx)
fmt.Println(res)
res, err = s.dao.GetCompanyCresitsList(ctx)
return
}
\ No newline at end of file
......@@ -50,3 +50,35 @@
[2019/11/21 17:35:20.751] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 17:37:29.678] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 17:59:02.082] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 18:45:56.411] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 18:46:48.980] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 18:49:08.615] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 18:56:20.039] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:00:25.701] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:01:09.443] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:01:30.621] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:08:30.137] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:10:13.056] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:10:41.757] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:13:46.905] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:17:28.590] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:18:15.720] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:18:51.319] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:20:34.017] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:21:37.742] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:28:22.747] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:28:53.162] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:29:07.819] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:30:37.659] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:30:48.842] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:34:11.613] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:25] caipu-server start
[2019/11/21 19:34:22.510] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:35:55.724] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:39:18.213] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:52:17.932] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:54:13.744] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:57:39.836] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 19:58:17.249] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 20:00:02.765] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 20:00:14.754] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/21 20:06:30.516] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:27] caipu-server start
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