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
348caae3
authored
Dec 05, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改通道不正确
parent
bae7fedd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
166 additions
and
123 deletions
cmd/static/Common.go
cmd/static/main.go
go.mod
go.sum
cmd/static/Common.go
0 → 100644
View file @
348caae3
package
main
import
(
"context"
"fmt"
"kaopu-server/internal/dao"
"kaopu-server/internal/service"
"strconv"
"time"
)
//计算单一项总的静态分
func
SetSumScore
(
c
context
.
Context
)
{
com_credits
.
Id
=
insertScoreMsg
.
ComCreditsId
com_credits
.
StaticCreditScore
=
CompanyInfo
()
+
AddScore
()
+
EnterPriseCredit
()
+
HistoryBussiness
()
+
PersonalCredit
()
connect
:=
dao
.
New
()
_
,
err
:=
connect
.
UpdateStaticSumScores
(
c
,
com_credits
)
fmt
.
Print
(
err
)
}
//协程增加分值记录
func
InsertRecord
(
c
context
.
Context
)
{
for
insertScoreMsgRecord
:=
range
socreRecordChan
{
//声明service层
svc
:=
service
.
New
()
//CurrentScore64 := float64(insertScoreMsgRecord.CurrentScore)
//插入数据
//if !math.IsNaN(CurrentScore64) && CurrentScore64 != 0 {
//}
//svc.InsertScores(c,insertScoreMsgRecord)
insertId
,
err
:=
svc
.
InsertScores
(
c
,
insertScoreMsgRecord
)
if
err
!=
nil
{
fmt
.
Print
(
err
)
}
//fmt.Print(err)
fmt
.
Print
(
insertId
)
}
defer
wg
.
Done
()
}
//设置插入的分数头
func
SetInsertScoreChanFooter
(
_typy
,
project_pid
,
project_id
int8
)
{
insertScoreMsg
.
Type
,
insertScoreMsg
.
ProjectPid
,
insertScoreMsg
.
ProjectId
=
_typy
,
project_pid
,
project_id
socreRecordChan
<-
insertScoreMsg
}
//获取详细的计算基本数据
func
GetCompanyRunInfo
(
c
context
.
Context
)
{
//声明service层
connect
:=
dao
.
New
()
companyBasicInfo
,
_
=
connect
.
GetCompanyBaseInfoByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
companySoreFields
,
_
=
connect
.
GetCompanyScoreFieldsByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
companyAddScore
,
_
=
connect
.
GetCompanyAddSoreByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
basicInfo
,
_
=
connect
.
GetBasicInfoByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
}
func
GetTimeStamp
()(
timestamp
int64
)
{
return
time
.
Now
()
.
Unix
()
}
func
StringTurnInt64
(
val
string
)
(
int64
)
{
intval
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
64
)
return
intval
}
func
StringTurnFloat64
(
val
string
)(
float64
)
{
floatval
,
_
:=
strconv
.
ParseFloat
(
val
,
64
)
return
floatval
}
func
getModelByProjectId
(
projectId
int64
)(
modelInfo
map
[
string
]
string
)
{
ctx
:=
context
.
Background
()
connect
:=
dao
.
New
()
res
,
_
:=
connect
.
GetCompanyModelByProjectid
(
ctx
,
1
)
return
res
}
//设置分数
func
setScore
(
curretScoreRelace
float64
,
weightReplace
float64
)
{
insertScoreMsg
.
TotalScore
=
curretScoreRelace
//设置分数
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
CurrentScore
=
curretScoreRelace
*
weightReplace
,
curretScoreRelace
*
weightReplace
insertScoreMsg
.
Weight
=
weightReplace
}
//设置project总分
func
SetProjectScore
(
totalScoreReplace
[
20
]
float64
,
weightReplace
float64
,
fullScore
float64
)(
finalScore
float64
)
{
var
(
sumScore
float64
=
0
joinNum
float64
=
0
)
//查找出所有不是0的分值
for
i
:=
0
;
i
<
len
(
totalScoreReplace
)
;
i
++
{
if
totalScoreReplace
[
i
]
>
0
{
joinNum
+=
1
sumScore
+=
totalScoreReplace
[
i
]
*
weightReplace
}
}
insertScoreMsg
.
CurrentScore
=
sumScore
//如果是0则不判断了
if
sumScore
==
0
{
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
FinalScore
=
0
,
0
}
else
{
//如果最后金额大于满分,则算为最满分
if
sumScore
>
fullScore
{
insertScoreMsg
.
TotalScore
=
fullScore
}
else
{
insertScoreMsg
.
TotalScore
=
sumScore
}
//经过权重计算之后的总分值
insertScoreMsg
.
FinalScore
=
sumScore
/
joinNum
}
insertScoreMsg
.
Weight
=
weightReplace
return
insertScoreMsg
.
FinalScore
}
\ No newline at end of file
cmd/static/main.go
View file @
348caae3
...
...
@@ -2,16 +2,15 @@ package main
import
(
"context"
"encoding/json"
"flag"
"fmt"
"
kaopu-server/internal/dao
"
"
github.com/ichunt2019/go-msgserver/utils/rabbitmq
"
"kaopu-server/internal/logic"
"kaopu-server/internal/model"
"kaopu-server/internal/service"
"strconv"
"sync"
"time"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq"
)
...
...
@@ -42,6 +41,11 @@ type RecvPro struct {
}
type
RabbitMsg
struct
{
ComCreditsId
string
`json:"com_credits_id"`
ErpCompanyCode
string
`json:"erp_company_code"`
}
...
...
@@ -49,15 +53,17 @@ func main() {
//获取config
logic
.
GetConfig
()
//设置协程数量
wg
.
Add
(
1
)
flag
.
StringVar
(
&
runtype
,
"runtype"
,
"one"
,
"default config path"
)
if
runtype
==
"one"
{
//设置协程数量
wg
.
Add
(
1
)
c
:=
context
.
Background
()
go
InsertRecord
(
c
)
flag
.
StringVar
(
&
runtype
,
"runtype"
,
"one"
,
"default config path"
)
c
:=
context
.
Background
()
go
InsertRecord
(
c
)
if
runtype
==
"one"
{
//调用服务获取公司信息,然后进行全局赋值
svc
:=
service
.
New
()
companyData
,
_
=
svc
.
GetCompanyCresitsList
(
c
)
...
...
@@ -69,13 +75,19 @@ func main() {
SetSumScore
(
c
)
break
}
//赋值完关闭通道
close
(
socreRecordChan
)
wg
.
Wait
()
}
else
{
t
:=
&
RecvPro
{}
queueExchange
:=
&
rabbitmq
.
QueueExchange
{
"fengkong_static_count"
,
"fengkong_static_count"
,
"
b_test_rabbit_mq
"
,
"
fengkong_exchange
"
,
"direct"
,
"amqp://guest:guest@192.168.2.232:5672/"
,
}
...
...
@@ -92,133 +104,38 @@ func main() {
}
fmt
.
Print
(
"待补充rabbitmq"
)
}
//赋值完关闭通道
close
(
socreRecordChan
)
wg
.
Wait
()
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
error
{
fmt
.
Println
(
string
(
dataByte
))
//return errors.New("顶顶顶顶")
return
nil
}
//转成json串
var
rbm
RabbitMsg
json
.
Unmarshal
(
dataByte
,
&
rbm
)
//计算单一项总的静态分
func
SetSumScore
(
c
context
.
Context
)
{
com_credits
.
Id
=
insertScoreMsg
.
ComCreditsId
com_credits
.
StaticCreditScore
=
CompanyInfo
()
+
AddScore
()
+
EnterPriseCredit
()
+
HistoryBussiness
()
+
PersonalCredit
()
connect
:=
dao
.
New
()
connect
.
UpdateStaticSumScores
(
c
,
com_credits
)
}
fmt
.
Print
(
rbm
)
socreRecordChan
=
make
(
chan
model
.
Scores
)
//设置协程数量
wg
.
Add
(
1
)
//协程增加分值记录
func
InsertRecord
(
c
context
.
Context
)
{
for
insertScoreMsgRecord
:=
range
socreRecordChan
{
//声明service层
svc
:=
service
.
New
()
//CurrentScore64 := float64(insertScoreMsgRecord.CurrentScore)
//插入数据
//if !math.IsNaN(CurrentScore64) && CurrentScore64 != 0 {
//}
//svc.InsertScores(c,insertScoreMsgRecord)
insertId
,
err
:=
svc
.
InsertScores
(
c
,
insertScoreMsgRecord
)
if
err
!=
nil
{
fmt
.
Print
(
err
)
}
//fmt.Print(err)
fmt
.
Print
(
insertId
)
}
defer
wg
.
Done
()
}
//设置插入的分数头
func
SetInsertScoreChanFooter
(
_typy
,
project_pid
,
project_id
int8
)
{
insertScoreMsg
.
Type
,
insertScoreMsg
.
ProjectPid
,
insertScoreMsg
.
ProjectId
=
_typy
,
project_pid
,
project_id
socreRecordChan
<-
insertScoreMsg
}
//获取详细的计算基本数据
func
GetCompanyRunInfo
(
c
context
.
Context
)
{
//声明service层
connect
:=
dao
.
New
()
companyBasicInfo
,
_
=
connect
.
GetCompanyBaseInfoByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
companySoreFields
,
_
=
connect
.
GetCompanyScoreFieldsByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
companyAddScore
,
_
=
connect
.
GetCompanyAddSoreByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
basicInfo
,
_
=
connect
.
GetBasicInfoByCid
(
c
,
insertScoreMsg
.
ComCreditsId
)
}
func
GetTimeStamp
()(
timestamp
int64
)
{
return
time
.
Now
()
.
Unix
()
}
func
StringTurnInt64
(
val
string
)
(
int64
)
{
intval
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
64
)
return
intval
}
func
StringTurnFloat64
(
val
string
)(
float64
)
{
floatval
,
_
:=
strconv
.
ParseFloat
(
val
,
64
)
return
floatval
}
c
:=
context
.
Background
()
go
InsertRecord
(
c
)
func
getModelByProjectId
(
projectId
int64
)(
modelInfo
map
[
string
]
string
)
{
ctx
:=
context
.
Background
()
connect
:=
dao
.
New
()
res
,
_
:=
connect
.
GetCompanyModelByProjectid
(
ctx
,
1
)
return
res
}
insertScoreMsg
.
ComCreditsId
=
StringTurnInt64
(
rbm
.
ComCreditsId
)
GetCompanyRunInfo
(
c
)
SetSumScore
(
c
)
//设置分数
func
setScore
(
curretScoreRelace
float64
,
weightReplace
float64
)
{
insertScoreMsg
.
TotalScore
=
curretScoreRelace
//赋值完关闭通道
close
(
socreRecordChan
)
wg
.
Wait
()
//设置分数
insertScoreMsg
.
FinalScore
,
insertScoreMsg
.
CurrentScore
=
curretScoreRelace
*
weightReplace
,
curretScoreRelace
*
weightReplace
insertScoreMsg
.
Weight
=
weightReplace
return
nil
}
//设置project总分
func
SetProjectScore
(
totalScoreReplace
[
20
]
float64
,
weightReplace
float64
,
fullScore
float64
)(
finalScore
float64
)
{
var
(
sumScore
float64
=
0
joinNum
float64
=
0
)
//查找出所有不是0的分值
for
i
:=
0
;
i
<
len
(
totalScoreReplace
)
;
i
++
{
if
totalScoreReplace
[
i
]
>
0
{
joinNum
+=
1
sumScore
+=
totalScoreReplace
[
i
]
*
weightReplace
}
}
insertScoreMsg
.
CurrentScore
=
sumScore
//如果是0则不判断了
if
sumScore
==
0
{
insertScoreMsg
.
TotalScore
,
insertScoreMsg
.
FinalScore
=
0
,
0
}
else
{
//如果最后金额大于满分,则算为最满分
if
sumScore
>
fullScore
{
insertScoreMsg
.
TotalScore
=
fullScore
}
else
{
insertScoreMsg
.
TotalScore
=
sumScore
}
//经过权重计算之后的总分值
insertScoreMsg
.
FinalScore
=
sumScore
/
joinNum
}
insertScoreMsg
.
Weight
=
weightReplace
return
insertScoreMsg
.
FinalScore
}
\ No newline at end of file
go.mod
View file @
348caae3
...
...
@@ -4,7 +4,7 @@ go 1.12
require (
github.com/bilibili/kratos v0.3.1
github.com/ichunt2019/go-msgserver v0.0.0-201912040
53231-bd327f4f8ff1
github.com/ichunt2019/go-msgserver v0.0.0-201912040
61508-2e5c6c0df17a
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/errors v0.8.1
)
go.sum
View file @
348caae3
...
...
@@ -103,6 +103,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ichunt2019/go-msgserver v0.0.0-20191204053231-bd327f4f8ff1 h1:UK7gMV/AS+d3p0wFQLXndXyek3FUIYxUZjPTyx4tZ2g=
github.com/ichunt2019/go-msgserver v0.0.0-20191204053231-bd327f4f8ff1/go.mod h1:fWAvbry0W9nhmkqgT2agwRqYCWlguUJXgy2rgoWOUmA=
github.com/ichunt2019/go-msgserver v0.0.0-20191204061508-2e5c6c0df17a h1:9wVfU589VXniFJUsmGPaBLUx349G1UsxO//Qh26gdyo=
github.com/ichunt2019/go-msgserver v0.0.0-20191204061508-2e5c6c0df17a/go.mod h1:fWAvbry0W9nhmkqgT2agwRqYCWlguUJXgy2rgoWOUmA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
...
...
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