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
2ddaa705
authored
Nov 26, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
解决协程不及时关闭的问题
parent
f0337fa7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
30 deletions
cmd/static/company_info.go
cmd/static/main.go
logs/info.log
cmd/static/company_info.go
View file @
2ddaa705
package
main
var
(
currentScore
float32
totalScore
float32
totalScore
[
7
]
float32
)
...
...
@@ -13,8 +10,6 @@ var(
//公司信息计算
func
CompanyInfo
()
{
totalScore
=
0
EstablishmentTime
()
CompanyNature
()
ChangeslegalInFiveYears
()
...
...
@@ -22,8 +17,22 @@ func CompanyInfo() {
AnnualTaxRate
()
lawsuitsInPastTwoYars
()
NumberOfSocial
()
var
(
sumScore
float32
=
0
joinNum
float32
=
0
)
//查找出所有不是0的分值
for
i
:=
0
;
i
<
len
(
totalScore
)
;
i
++
{
if
totalScore
[
i
]
!=
0
{
joinNum
+=
1
sumScore
+=
totalScore
[
i
]
*
0.5
}
}
//经过权重计算之后的总分值
sumScore
=
sumScore
/
joinNum
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
CurrentScore
=
totalScore
,
totalScore
,
total
Score
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
CurrentScore
=
sumScore
,
sumScore
,
sum
Score
insertScoreMsg
.
Weight
=
50
setInserScoreChanFooter
(
1
,
0
,
1
)
}
...
...
@@ -42,7 +51,7 @@ func EstablishmentTime() {
currentScore
=
0
}
totalScore
+
=
currentScore
totalScore
[
0
]
=
currentScore
//设置分数
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
CurrentScore
=
currentScore
,
currentScore
,
currentScore
...
...
@@ -62,7 +71,8 @@ func CompanyNature() {
currentScore
=
1
}
totalScore
+=
currentScore
totalScore
[
1
]
=
currentScore
//设置分数
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
CurrentScore
=
currentScore
,
currentScore
,
currentScore
...
...
@@ -83,7 +93,8 @@ func ChangeslegalInFiveYears() {
currentScore
=
0
}
totalScore
+=
currentScore
totalScore
[
2
]
=
currentScore
setInserScoreChanFooter
(
1
,
1
,
10
)
}
...
...
@@ -101,7 +112,8 @@ func RegisteredCapital() {
currentScore
=
1
}
totalScore
+=
currentScore
totalScore
[
3
]
=
currentScore
setInserScoreChanFooter
(
1
,
1
,
11
)
}
...
...
@@ -117,7 +129,8 @@ func AnnualTaxRate() {
currentScore
=
1
}
totalScore
+=
currentScore
totalScore
[
4
]
=
currentScore
setInserScoreChanFooter
(
1
,
1
,
12
)
}
...
...
@@ -131,7 +144,8 @@ func lawsuitsInPastTwoYars() {
currentScore
=
2
}
totalScore
+=
currentScore
totalScore
[
5
]
=
currentScore
setInserScoreChanFooter
(
1
,
1
,
13
)
}
...
...
@@ -146,7 +160,8 @@ func NumberOfSocial() {
currentScore
=
0
}
totalScore
+=
currentScore
totalScore
[
6
]
=
currentScore
setInserScoreChanFooter
(
1
,
1
,
14
)
}
...
...
cmd/static/main.go
View file @
2ddaa705
...
...
@@ -10,6 +10,7 @@ import (
"kaopu-server/internal/model"
"kaopu-server/internal/service"
"strconv"
"sync"
"time"
)
...
...
@@ -18,13 +19,13 @@ var (
//获取的公司信息
companyData
[]
map
[
string
]
string
//插入分值的通道,限制一千,超过等待
socreRecordChan
=
make
(
chan
model
.
Scores
,
1000
)
socreRecordChan
=
make
(
chan
model
.
Scores
)
//分数的数据
insertScoreMsg
model
.
Scores
//公司的详细数据
companyBasicInfo
map
[
string
]
string
isOver
=
make
(
chan
int
)
//设置等待
wg
sync
.
WaitGroup
)
...
...
@@ -32,7 +33,10 @@ var (
func
main
()
{
//获取config
getConfig
()
//设置协程数量
wg
.
Add
(
1
)
go
insertRecord
()
svc
:=
service
.
New
()
...
...
@@ -46,18 +50,16 @@ func main() {
insertScoreMsg
.
ComCreditsId
=
stringTurnInt64
(
v
[
"id"
])
companyBasicInfo
,
_
=
svc
.
GetCompanyBaseInfoByCid
(
ctx
,
insertScoreMsg
.
ComCreditsId
)
CompanyInfo
()
//
EnterPriseCredit()
EnterPriseCredit
()
//HistoryBussiness()
//PersonalCredit()
//AddScore()
}
//赋值完关闭通道
close
(
socreRecordChan
)
// 判断所有协程是否退出
for
range
isOver
{
close
(
isOver
)
}
wg
.
Wait
()
}
...
...
@@ -78,19 +80,18 @@ func getConfig() {
//协程增加分值记录
func
insertRecord
()
{
for
{
ctx
:=
context
.
Background
()
for
insertScoreMsg
:=
range
socreRecordChan
{
//声明service层
connect
:=
dao
.
New
()
ctx
:=
context
.
Background
()
// 从通道中拿出消息
insertScoreMsg
:=
<-
socreRecordChan
//插入数据
insertId
,
err
:=
connect
.
InsertScores
(
ctx
,
insertScoreMsg
)
fmt
.
Print
(
err
)
fmt
.
Print
(
insertId
)
//插入数据
}
isOver
<-
1
}
defer
wg
.
Done
()
}
//设置插入的分数头
...
...
logs/info.log
View file @
2ddaa705
...
...
@@ -281,3 +281,33 @@
[2019/11/25 19:37:02.573] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:70] caipu-server start
[2019/11/25 19:46:54.194] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:74] caipu-server start
[2019/11/25 19:48:42.586] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:74] caipu-server start
[2019/11/25 19:52:31.401] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/25 19:54:53.134] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/25 19:55:21.030] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/25 19:56:50.837] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/25 19:59:02.549] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/25 19:59:10.735] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/25 19:59:20.506] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:72] caipu-server start
[2019/11/25 19:59:55.539] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/25 20:00:13.941] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/25 20:00:58.563] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/25 20:02:25.883] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/26 09:59:52.203] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/26 10:00:47.411] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/26 10:02:52.480] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/26 10:03:37.917] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] caipu-server start
[2019/11/26 10:13:09.595] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/26 10:13:32.899] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:75] caipu-server start
[2019/11/26 10:20:01.059] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:73] caipu-server start
[2019/11/26 10:21:18.273] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:74] caipu-server start
[2019/11/26 10:25:36.417] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:73] caipu-server start
[2019/11/26 10:26:24.076] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:73] caipu-server start
[2019/11/26 10:53:56.988] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:78] caipu-server start
[2019/11/26 10:55:53.465] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:78] caipu-server start
[2019/11/26 10:59:33.908] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:70] caipu-server start
[2019/11/26 11:04:01.646] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:70] caipu-server start
[2019/11/26 11:04:35.443] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:69] caipu-server start
[2019/11/26 11:05:16.839] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:69] caipu-server start
[2019/11/26 11:11:13.459] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:69] caipu-server start
[2019/11/26 11:20:03.328] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:70] caipu-server start
[2019/11/26 11:22:26.430] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:76] 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