Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
kaopu-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
713c2d0a
authored
Nov 22, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善字段筛选
parent
2aabeefc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
36 deletions
cmd/static/main.go
internal/dao/com_credits.go
internal/dao/common.go
logs/info.log
cmd/static/main.go
View file @
713c2d0a
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/dao"
"kaopu-server/internal/service"
)
...
...
@@ -21,7 +22,8 @@ func main() {
//声明service层
svc
:=
service
.
New
()
ctx
:=
context
.
Background
()
//调用会员服务
//调用服务获取公司信息
dao
.
SqlField
=
"id"
userdata
,
_
:=
svc
.
GetCompanyCresitsList
(
ctx
)
fmt
.
Print
(
userdata
)
}
...
...
internal/dao/com_credits.go
View file @
713c2d0a
...
...
@@ -7,46 +7,12 @@ import (
"github.com/pkg/errors"
)
//根据指针行获取所有的参数
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
]
}
row
:=
make
(
map
[
string
]
interface
{})
for
rows
.
Next
(){
err
=
rows
.
Scan
(
scans
...
)
if
err
!=
nil
{
fmt
.
Println
(
"scan fail,err:"
,
err
)
return
}
for
k
,
v
:=
range
vals
{
key
:=
cols
[
k
]
row
[
key
]
=
v
}
res
=
append
(
res
,
row
)
}
return
}
//列表方式获取会员信息
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
{
if
rows
,
err
=
d
.
db
.
Query
(
ctx
,
"SELECT
"
+
SqlField
+
"
FROM lie_com_credits "
);
err
!=
nil
{
err
=
errors
.
WithStack
(
err
)
return
}
...
...
internal/dao/common.go
0 → 100644
View file @
713c2d0a
package
dao
import
(
"fmt"
"github.com/bilibili/kratos/pkg/database/sql"
)
//定义一些sql执行语句
var
(
//需要查询的字段,默认为*
SqlField
string
=
"*"
)
//根据指针行获取所有的参数
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
]
}
row
:=
make
(
map
[
string
]
interface
{})
for
rows
.
Next
(){
err
=
rows
.
Scan
(
scans
...
)
if
err
!=
nil
{
fmt
.
Println
(
"scan fail,err:"
,
err
)
return
}
for
k
,
v
:=
range
vals
{
key
:=
cols
[
k
]
row
[
key
]
=
v
}
res
=
append
(
res
,
row
)
}
return
}
\ No newline at end of file
logs/info.log
View file @
713c2d0a
...
...
@@ -123,3 +123,7 @@
[2019/11/22 11:49:30.150] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/22 11:50:03.869] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:26] caipu-server start
[2019/11/22 13:28:22.506] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:39] caipu-server start
[2019/11/22 13:49:40.591] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:42] caipu-server start
[2019/11/22 13:49:46.256] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:42] caipu-server start
[2019/11/22 13:50:19.103] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:41] caipu-server start
[2019/11/22 13:50:24.217] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:42] caipu-server start
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment