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
90dc6642
authored
Nov 25, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加sql插入
parent
c66f1d59
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
28 deletions
cmd/static/company_info.go
cmd/static/main.go
internal/dao/dao.go
internal/dao/scores.go
internal/service/service.go
logs/info.log
cmd/static/company_info.go
View file @
90dc6642
...
...
@@ -16,12 +16,13 @@ func CompanyInfo() {
//成立时间(1分)
func
EstablishmentTime
()
{
setInserScoreHeader
(
1
,
1
,
8
)
inserScoreMsg
.
TotalScore
=
5
inserScoreMsg
.
FinalScore
=
5
inserScoreMsg
.
CurrentScore
=
2
inserScoreMsg
.
Weight
=
50
inserScoreMsg
.
ComCreditsId
=
2
socreRecordChan
<-
inserScoreMsg
insertScoreMsg
.
TotalScore
=
5
insertScoreMsg
.
FinalScore
=
5
insertScoreMsg
.
CurrentScore
=
2
insertScoreMsg
.
Weight
=
50
insertScoreMsg
.
ComCreditsId
=
2
socreRecordChan
<-
insertScoreMsg
}
...
...
cmd/static/main.go
View file @
90dc6642
...
...
@@ -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/model"
"kaopu-server/internal/service"
"time"
...
...
@@ -17,8 +18,8 @@ var (
companyData
[]
map
[
string
]
interface
{}
//插入分值的通道,限制一千,超过等待
socreRecordChan
=
make
(
chan
model
.
Scores
,
1000
)
//
inserScoreMsg
model
.
Scores
//
分数的数据
inser
t
ScoreMsg
model
.
Scores
)
...
...
@@ -29,17 +30,23 @@ func main() {
getConfig
()
go
insertRecord
()
svc
:=
service
.
New
()
ctx
:=
context
.
Background
()
//调用服务获取公司信息,然后进行全局赋值
companyData
,
_
=
svc
.
GetCompanyCresitsList
(
ctx
)
CompanyInfo
()
//insertId,err := svc.InsertScores(ctx,insertScoreMsg)
//fmt.Print(err)
//fmt.Print(insertId)
//fmt.Print(companyData)
//EnterPriseCredit()
//HistoryBussiness()
//PersonalCredit()
//AddScore()
time
.
Sleep
(
1
*
time
.
Millisecond
)
//延迟100秒用来执行协程的错误返回
time
.
Sleep
(
100000
*
time
.
Millisecond
)
}
...
...
@@ -61,22 +68,21 @@ func getConfig() {
func
insertRecord
()
{
//声明service层
svc
:=
service
.
New
()
connect
:=
dao
.
New
()
ctx
:=
context
.
Background
()
for
{
// 从通道中拿出消息
insertRecord
:=
<-
socreRecordChan
svc
.
in
fmt
.
Print
(
insertRecord
)
insertScoreMsg
:=
<-
socreRecordChan
insertId
,
err
:=
connect
.
InsertScores
(
ctx
,
insertScoreMsg
)
fmt
.
Print
(
err
)
fmt
.
Print
(
insertId
)
//插入数据
}
}
//设置插入的分数头
func
setInserScoreHeader
(
_typy
,
project_pid
,
project_id
int8
)
{
inserScoreMsg
.
Type
=
_typy
inserScoreMsg
.
ProjectPid
=
project_pid
inserScoreMsg
.
ProjectId
=
project_id
inser
t
ScoreMsg
.
Type
=
_typy
inser
t
ScoreMsg
.
ProjectPid
=
project_pid
inser
t
ScoreMsg
.
ProjectId
=
project_id
}
\ No newline at end of file
internal/dao/dao.go
View file @
90dc6642
...
...
@@ -22,7 +22,7 @@ type (
//---静态开始
GetCompanyCresitsList
(
ctx
context
.
Context
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
InsertScores
(
ctx
context
.
Context
,
score
*
model
.
Scores
)
(
insertId
int64
,
err
error
)
InsertScores
(
ctx
context
.
Context
,
score
model
.
Scores
)
(
insertId
int64
,
err
error
)
//---静态结束
}
...
...
@@ -37,6 +37,7 @@ type dao struct {
mcExpire
int32
}
func
checkErr
(
err
error
)
{
if
err
!=
nil
{
panic
(
err
)
...
...
internal/dao/scores.go
View file @
90dc6642
...
...
@@ -4,19 +4,23 @@ import (
"context"
"fmt"
"kaopu-server/internal/model"
"github.com/bilibili/kratos/pkg/log"
)
//增加记录
func
(
d
*
dao
)
insertScores
(
ctx
context
.
Context
,
score
*
model
.
Scores
)
(
res
int64
,
err
error
)
{
func
(
d
*
dao
)
InsertScores
(
ctx
context
.
Context
,
score
model
.
Scores
)
(
insertId
int64
,
err
error
)
{
stmt
,
_
:=
d
.
db
.
Prepare
(
"INSERT INTO chat_list (roomstr, urid,srid) VALUES (?,?,?)"
)
insertSql
:=
"INSERT INTO `lie_scores` (`type`)VALUES(?)"
row
,
err
:=
stmt
.
Exec
(
ctx
,
score
.
CreateTime
,
score
.
CurrentScore
)
if
err
!=
nil
{
fmt
.
Println
(
"select fail,err:"
,
err
)
row
,
err
:=
d
.
db
.
Exec
(
ctx
,
insertSql
,
1
)
fmt
.
Print
(
11111
)
if
err
!=
nil
{
log
.
Error
(
"db.DemoExec.Exec(%s) error(%v)"
,
insertSql
,
err
)
return
}
row
.
LastInsertId
()
defer
d
.
db
.
Close
()
res
,
_
=
row
.
LastInsertId
()
return
}
\ No newline at end of file
internal/service/service.go
View file @
90dc6642
...
...
@@ -71,10 +71,13 @@ func (s *Service) GetCompanyCresitsList(ctx context.Context) (res []map[string]i
}
//插入分数记录
func
(
s
*
Service
)
insertScores
(
ctx
context
.
Context
,
score
*
model
.
Scores
)
(
inser
Id
int64
,
err
error
)
{
func
(
s
*
Service
)
InsertScores
(
ctx
context
.
Context
,
score
model
.
Scores
)
(
insert
Id
int64
,
err
error
)
{
//调用DB方法,获取会员数据
inserId
,
_
=
s
.
dao
.
InsertScores
(
ctx
,
score
)
insertId
,
err
=
s
.
dao
.
InsertScores
(
ctx
,
score
)
if
err
!=
nil
{
panic
(
err
.
Error
())
// proper error handling instead of panic in your app
}
return
}
...
...
logs/info.log
View file @
90dc6642
This diff is collapsed.
Click to expand it.
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