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
382520b7
authored
Nov 28, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
1b7cf1a2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
26 deletions
cmd/dong/main.go
go.mod
internal/dao/scores.go
internal/dao/yuqi_dao.go
cmd/dong/main.go
View file @
382520b7
...
...
@@ -8,6 +8,8 @@ import (
"kaopu-server/internal/logic"
"fmt"
"os"
"strconv"
"sync"
)
func
main
()
{
...
...
@@ -40,18 +42,46 @@ func main() {
}
ctx
:=
context
.
Background
()
//上下文
if
mod
>
0
{
runTask
(
mod
,
ctx
)
}
else
{
var
wg
sync
.
WaitGroup
for
k
,
_
:=
range
model_dong
{
// 开启协程
wg
.
Add
(
1
)
go
func
(
k
int
)
{
fmt
.
Println
(
"--开始协程:"
+
strconv
.
Itoa
(
k
))
runTask
(
k
,
ctx
)
//运行任务
fmt
.
Println
(
"--结束协程:"
+
strconv
.
Itoa
(
k
))
defer
wg
.
Add
(
-
1
)
}(
k
)
}
wg
.
Wait
()
fmt
.
Println
(
"
\r\n
所有任务已经完成"
)
}
}
/*
* 根据类型分别跑任务
*/
func
runTask
(
mod
int
,
ctx
context
.
Context
)
{
svc
:=
service
.
New
()
switch
mod
{
case
35
:
logic
.
Loginfo
(
"逾期率统计开始"
,
"_yuqilv"
);
svc
.
CountYuqiRate
(
ctx
,
mod
,
""
);
case
36
:
case
36
:
logic
.
Loginfo
(
"发生逾期笔数率统计开始"
,
"_yuqibi"
);
svc
.
CountYuqiBi
(
ctx
,
mod
,
""
);
default
:
fmt
.
Println
(
mod
)
//实例化所有
return
}
return
}
go.mod
0 → 100644
View file @
382520b7
module kaopu-server
go 1.12
require (
github.com/bilibili/kratos v0.3.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/errors v0.8.1
)
internal/dao/scores.go
View file @
382520b7
...
...
@@ -2,7 +2,6 @@ package dao
import
(
"context"
"fmt"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/model"
"time"
...
...
@@ -18,8 +17,8 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
)
err
=
d
.
db
.
QueryRow
(
ctx
,
"select id from lie_scores where `type` = ? and project_pid = ? and project_id = ? and com_credits_id = ? limit 0,1"
,
score
.
Type
,
score
.
ProjectPid
,
score
.
ProjectId
,
score
.
ComCreditsId
)
.
Scan
(
&
exitId
)
if
err
!=
nil
{
fmt
.
Print
(
err
)
fmt
.
Print
(
"save list fail"
)
//
fmt.Print(err)
//
fmt.Print("save list fail")
}
if
exitId
==
0
{
...
...
internal/dao/yuqi_dao.go
View file @
382520b7
...
...
@@ -32,11 +32,19 @@ func (d *dao) CountYuqiRate(ctx context.Context,project_id_c int,erp_company_cod
//查询逾期率项目配置
sql_str1
:=
fmt
.
Sprintf
(
_sql1
,
strconv
.
Itoa
(
project_id_c
))
yuqilv_project
,
err
:=
d
.
QueryOne
(
ctx
,
1
,
sql_str1
)
if
yuqilv_project
==
nil
{
logic
.
Loginfo
(
"不存在该项目配置lie_model ,project_id:"
+
strconv
.
Itoa
(
project_id_c
),
_log_pre_yuqilv
)
return
}
weight
,
_
:=
strconv
.
ParseFloat
(
yuqilv_project
[
"weight"
],
64
)
//查询逾期率项目详情
sql_str4
:=
fmt
.
Sprintf
(
_sql4
,
strconv
.
Itoa
(
project_id_c
))
modelItems
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
sql_str4
)
if
modelItems
==
nil
{
logic
.
Loginfo
(
"不存在该项目配置详情lie_model_items,project_id:"
+
strconv
.
Itoa
(
project_id_c
),
_log_pre_yuqilv
)
return
}
//查询当前申请的所有公司
if
erp_company_code
==
""
{
...
...
@@ -74,6 +82,10 @@ func (d *dao) CountYuqiRate(ctx context.Context,project_id_c int,erp_company_cod
score_one
=
logic
.
MyFloat64
(
y
[
"score"
])
//得到的分数
}
}
if
score_one
==
0
{
fmt
.
Print
(
"
\r\n
逾期金额率不存在对应梯度,erp_company_code:"
+
v
[
"erp_company_code"
]
+
" 笔数率:"
+
logic
.
MyFloat64ToStr
(
yuqilv
))
continue
;
}
//拼接最终得分
final_score
=
weight
*
0.01
*
score_one
...
...
@@ -107,19 +119,24 @@ func (d *dao) CountYuqiRate(ctx context.Context,project_id_c int,erp_company_cod
func
(
d
*
dao
)
CountYuqiBi
(
ctx
context
.
Context
,
project_id_c
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
var
(
final_score
float64
score_one
float64
=
0
;
//分数
_sql2
string
;
//
)
//查询逾期率项目配置
sql_str1
:=
fmt
.
Sprintf
(
_sql1
,
strconv
.
Itoa
(
project_id_c
))
yuqilv_project
,
err
:=
d
.
QueryOne
(
ctx
,
1
,
sql_str1
)
if
yuqilv_project
==
nil
{
logic
.
Loginfo
(
"不存在该项目配置lie_model ,project_id:"
+
strconv
.
Itoa
(
project_id_c
),
_log_pre_yuqibi
)
return
}
weight
,
_
:=
strconv
.
ParseFloat
(
yuqilv_project
[
"weight"
],
64
)
//查询逾期率项目详情
sql_str4
:=
fmt
.
Sprintf
(
_sql4
,
strconv
.
Itoa
(
project_id_c
))
modelItems
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
sql_str4
)
if
modelItems
==
nil
{
logic
.
Loginfo
(
"不存在该项目配置详情lie_model_items,project_id:"
+
strconv
.
Itoa
(
project_id_c
),
_log_pre_yuqibi
)
return
}
//查询当前申请的所有公司
if
erp_company_code
==
""
{
_sql2
=
_sql2_1
...
...
@@ -129,35 +146,41 @@ func (d *dao) CountYuqiBi(ctx context.Context,project_id_c int,erp_company_code
company_info
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
_sql2
);
if
err
!=
nil
{
fmt
.
Println
(
"
\r\n
error:100
4
"
,
err
.
Error
())
fmt
.
Println
(
"
\r\n
error:100
5
"
,
err
.
Error
())
logic
.
Loginfo
(
"错误"
+
err
.
Error
(),
_log_pre_yuqibi
)
return
}
for
_
,
v
:=
range
company_info
{
//循环当前公司,计算各个公司逾期率
for
_
,
v
:=
range
company_info
{
//循环当前公司,计算各个公司逾期
笔数
率
if
v
[
"erp_company_code"
]
!=
""
{
//查询逾期笔数
yuqibi
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
fmt
.
Sprintf
(
_sql5
,
v
[
"erp_company_code"
]))
if
yuqibi
==
nil
{
//没有结果
fmt
.
Print
(
"
\r\n
公司编码:"
+
v
[
"erp_company_code"
]
+
"没有
预
期笔数,跳过"
)
if
yuqibi
[
"yuqibi"
]
==
"0"
{
//没有结果
fmt
.
Print
(
"
\r\n
公司编码:"
+
v
[
"erp_company_code"
]
+
"没有
逾
期笔数,跳过"
)
continue
}
//查询逾期笔数
allbi
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
fmt
.
Sprintf
(
_sql6
,
v
[
"erp_company_code"
]))
var
birate
float64
=
logic
.
MyFloat64
(
yuqibi
[
"yuqibi"
])
/
logic
.
MyFloat64
(
allbi
[
"allbi"
])
birate
:
=
logic
.
MyFloat64
(
yuqibi
[
"yuqibi"
])
/
logic
.
MyFloat64
(
allbi
[
"allbi"
])
//查询逾期率对应分数
//查询收款总笔数
var
score_one
float64
=
0
;
//对应梯度分数
for
_
,
y
:=
range
modelItems
{
ladder_range_min
,
_
:=
strconv
.
ParseFloat
(
y
[
"ladder_range_min"
],
64
)
//0.1
ladder_range_max
,
_
:=
strconv
.
ParseFloat
(
y
[
"ladder_range_max"
],
64
)
fmt
.
Print
(
"
\r\n\r\n
:"
,
ladder_range_min
,
ladder_range_max
,
0.2
)
if
(
ladder_range_min
<=
birate
&&
birate
<
ladder_range_max
)
{
score_one
=
logic
.
MyFloat64
(
y
[
"score"
])
//得到的分数
}
}
if
score_one
==
0
{
log1
:=
"
\r\n
逾期笔数率不存在对应梯度,erp_company_code:"
+
v
[
"erp_company_code"
]
+
" 笔数率:"
+
logic
.
MyFloat64ToStr
(
birate
)
fmt
.
Print
(
log1
)
logic
.
Loginfo
(
log1
,
_log_pre_yuqibi
)
continue
;
}
//拼接最终得分
final_score
=
weight
*
0.01
*
score_one
final_score
:
=
weight
*
0.01
*
score_one
var
scores
model
.
Scores
//插入分数结构体
scores
.
Type
=
2
;
...
...
@@ -169,19 +192,17 @@ func (d *dao) CountYuqiBi(ctx context.Context,project_id_c int,erp_company_code
scores
.
FinalScore
=
final_score
;
scores
.
ComCreditsId
=
logic
.
MyInt64
(
v
[
"id"
]);
fmt
.
Print
(
"
\r\n\r\n
结构体:"
,
score_one
)
insertid
,
err
:=
d
.
InsertScores
(
ctx
,
scores
)
if
err
!=
nil
{
logic
.
Loginfo
(
"错误:"
+
err
.
Error
(),
_log_pre_yuqibi
)
fmt
.
Print
(
"错误:"
+
err
.
Error
(),
insertid
)
}
var
log1
string
=
"统计逾期
率成功--公司编码:"
+
v
[
"erp_company_code"
]
+
"计算得分:"
+
logic
.
MyFloat64ToStr
(
score_one
)
+
" 最终得分:"
+
logic
.
MyFloat64ToStr
(
final_score
);
fmt
.
Print
(
log
1
)
logic
.
Loginfo
(
log
1
,
_log_pre_yuqibi
)
log2
:=
"统计逾期笔数
率成功--公司编码:"
+
v
[
"erp_company_code"
]
+
"计算得分:"
+
logic
.
MyFloat64ToStr
(
score_one
)
+
" 最终得分:"
+
logic
.
MyFloat64ToStr
(
final_score
);
fmt
.
Print
(
log
2
)
logic
.
Loginfo
(
log
2
,
_log_pre_yuqibi
)
}
}
logic
.
Loginfo
(
"统计逾期率完成"
,
_log_pre_yuqibi
)
logic
.
Loginfo
(
"统计逾期
笔数
率完成"
,
_log_pre_yuqibi
)
return
}
...
...
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