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
933b00df
authored
Nov 28, 2019
by
Joneq
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev' of
http://119.23.72.7/sunlong_v5/kaopu-server
into dev
parents
34402165
382520b7
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
186 additions
and
42 deletions
cmd/dong/main.go
go.mod
internal/dao/dao.go
internal/dao/scores.go
internal/dao/yuqi_dao.go
internal/logic/common.go
internal/logic/mylog.go
internal/service/dong_service.go
cmd/dong/main.go
View file @
933b00df
...
...
@@ -5,17 +5,15 @@ import (
"context"
"kaopu-server/internal/service"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/logic"
"time"
"fmt"
"os"
"strconv"
"sync"
)
func
main
()
{
logic
.
Loginfo
(
"逾期统计开始"
,
"_yuqilv_"
);
//获取输入参数
//获取输入参数s
var
mod
int
;
flag
.
IntVar
(
&
mod
,
"m"
,
0
,
"请输入模块id"
)
// 单独计算某个模块,默认计算全部,0计算全部
flag
.
Parse
()
...
...
@@ -44,21 +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
:
//计算逾期率
fmt
.
Println
(
"计算逾期率开始:"
+
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
))
svc
.
CountYuqi
(
ctx
,
mod
,
""
);
case
35
:
logic
.
Loginfo
(
"逾期率统计开始"
,
"_yuqilv"
);
svc
.
CountYuqiRate
(
ctx
,
mod
,
""
);
case
36
:
logic
.
Loginfo
(
"发生逾期笔数率统计开始"
,
"_yuqibi"
);
svc
.
CountYuqiBi
(
ctx
,
mod
,
""
);
default
:
fmt
.
Println
(
mod
)
//实例化所有
return
}
//初始化日志目录
log
.
Init
(
&
log
.
Config
{
Dir
:
"logs/"
})
defer
log
.
Close
()
log
.
Info
(
"caipu-server start"
)
return
}
}
go.mod
View file @
933b00df
...
...
@@ -4,7 +4,6 @@ go 1.12
require (
github.com/bilibili/kratos v0.3.1
github.com/goinggo/mapstructure v0.0.0-20140717182941-194205d9b4a9
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/errors v0.8.1
)
internal/dao/dao.go
View file @
933b00df
...
...
@@ -35,7 +35,10 @@ type (
GetCompanyModelByProjectid
(
c
context
.
Context
,
companyId
int64
)
(
r
map
[
string
]
string
,
err
error
)
//---静态结束
CountYuqi
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
//计算逾期
//---动态开始
CountYuqiRate
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
//计算逾期率
CountYuqiBi
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
//计算逾期笔数率
//---动态结束
}
)
...
...
internal/dao/scores.go
View file @
933b00df
...
...
@@ -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 @
933b00df
...
...
@@ -3,23 +3,26 @@ package dao
import
(
"context"
"fmt"
"os"
"kaopu-server/internal/model"
"kaopu-server/internal/logic"
"kaopu-server/internal/model"
"strconv"
)
const
(
_log_pre_yuqilv
=
"_yuqilv"
//日志文件前缀
_log_pre_yuqibi
=
"_yuqibi"
//日志文件前缀
_sql1
=
"select m.full_score,m.weight,m.max_score,p.id,p.pid from lie_model m,lie_project p where m.project_id=p.id and p.id=%s"
//查询项目配置
_sql2_1
=
"select id,erp_company_code,company_name from lie_com_credits order by id asc "
//查询公司所有信息
_sql2_1
=
"select id,erp_company_code,company_name from lie_com_credits
ddd
order by id asc "
//查询公司所有信息
_sql2_2
=
"select id,erp_company_code,company_name from lie_com_credits where erp_company_code = '%s' order by id asc "
//查询公司所有信息
_sql3
=
"select sum(delay_amount)/sum(order_amount) yuqilv from lie_basic_detail where erp_company_code='%s' "
//基础数据
_sql4
=
"select * from lie_model_items where project_id=%s "
//查询统计项目梯度详情
_sql5
=
"select count(1) yuqibi from lie_basic_detail where delay_amount>0 and erp_company_code='%s'"
//发生逾期笔数
_sql6
=
"select count(1) allbi from lie_basic_detail where return_amount>0 and erp_company_code='%s'"
//收款总笔数
)
//计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id_c
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
func
(
d
*
dao
)
CountYuqi
Rate
(
ctx
context
.
Context
,
project_id_c
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
var
(
final_score
float64
...
...
@@ -29,12 +32,19 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
//查询逾期率项目配置
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
)
//fmt.Print(sql_str4,modelItems)
if
modelItems
==
nil
{
logic
.
Loginfo
(
"不存在该项目配置详情lie_model_items,project_id:"
+
strconv
.
Itoa
(
project_id_c
),
_log_pre_yuqilv
)
return
}
//查询当前申请的所有公司
if
erp_company_code
==
""
{
...
...
@@ -45,7 +55,8 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
company_info
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
_sql2
);
if
err
!=
nil
{
fmt
.
Println
(
"
\r\n
error:1004"
,
err
)
fmt
.
Println
(
"
\r\n
error:1004"
,
err
.
Error
())
logic
.
Loginfo
(
"错误"
+
err
.
Error
(),
_log_pre_yuqilv
)
return
}
...
...
@@ -53,7 +64,6 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
if
v
[
"erp_company_code"
]
!=
""
{
//查询逾期率
sql3
:=
fmt
.
Sprintf
(
_sql3
,
v
[
"erp_company_code"
])
//fmt.Print("\r\n查询sql:"+sql3)
oneyu
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
sql3
)
if
oneyu
==
nil
{
//没有结果
fmt
.
Print
(
"
\r\n
公司编码:"
+
v
[
"erp_company_code"
]
+
"逾期金额率为空,跳过"
)
...
...
@@ -72,8 +82,10 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
score_one
=
logic
.
MyFloat64
(
y
[
"score"
])
//得到的分数
}
}
fmt
.
Print
(
"
\r\n\r\n
score_one:"
,
score_one
)
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
...
...
@@ -91,13 +103,106 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
insertid
,
err
:=
d
.
InsertScores
(
ctx
,
scores
)
if
err
!=
nil
{
fmt
.
Print
(
err
,
insertid
)
logic
.
Loginfo
(
"错误:"
+
err
.
Error
(),
_log_pre_yuqilv
)
fmt
.
Print
(
"错误:"
+
err
.
Error
(),
insertid
)
}
var
log1
string
=
"统计逾期率成功--公司编码:"
+
v
[
"erp_company_code"
]
+
"计算得分:"
+
logic
.
MyFloat64ToStr
(
score_one
)
+
" 最终得分:"
+
logic
.
MyFloat64ToStr
(
final_score
);
fmt
.
Print
(
log1
)
logic
.
Loginfo
(
log1
,
_log_pre_yuqilv
)
}
}
logic
.
Loginfo
(
"统计逾期率完成"
,
_log_pre_yuqilv
)
return
}
//发生逾期笔数率: 发生逾期笔数/收款总笔数
func
(
d
*
dao
)
CountYuqiBi
(
ctx
context
.
Context
,
project_id_c
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
var
(
_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
}
else
{
_sql2
=
fmt
.
Sprintf
(
_sql2_2
,
erp_company_code
)
//查询一个公司
}
company_info
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
_sql2
);
if
err
!=
nil
{
fmt
.
Println
(
"
\r\n
error:1005"
,
err
.
Error
())
logic
.
Loginfo
(
"错误"
+
err
.
Error
(),
_log_pre_yuqibi
)
return
}
for
_
,
v
:=
range
company_info
{
//循环当前公司,计算各个公司逾期笔数率
if
v
[
"erp_company_code"
]
!=
""
{
//查询逾期笔数
yuqibi
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
fmt
.
Sprintf
(
_sql5
,
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"
]))
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
)
if
(
ladder_range_min
<=
birate
&&
birate
<
ladder_range_max
)
{
score_one
=
logic
.
MyFloat64
(
y
[
"score"
])
//得到的分数
}
//fmt.Print(scores,weight,final_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
os
.
Exit
(
1
)
var
scores
model
.
Scores
//插入分数结构体
scores
.
Type
=
2
;
scores
.
ProjectPid
=
logic
.
MyInt8
(
yuqilv_project
[
"pid"
]);
scores
.
ProjectId
=
logic
.
MyInt8
(
yuqilv_project
[
"id"
]);
scores
.
TotalScore
=
score_one
;
scores
.
CurrentScore
=
score_one
;
scores
.
Weight
=
weight
;
scores
.
FinalScore
=
final_score
;
scores
.
ComCreditsId
=
logic
.
MyInt64
(
v
[
"id"
]);
insertid
,
err
:=
d
.
InsertScores
(
ctx
,
scores
)
if
err
!=
nil
{
logic
.
Loginfo
(
"错误:"
+
err
.
Error
(),
_log_pre_yuqibi
)
fmt
.
Print
(
"错误:"
+
err
.
Error
(),
insertid
)
}
log2
:=
"统计逾期笔数率成功--公司编码:"
+
v
[
"erp_company_code"
]
+
"计算得分:"
+
logic
.
MyFloat64ToStr
(
score_one
)
+
" 最终得分:"
+
logic
.
MyFloat64ToStr
(
final_score
);
fmt
.
Print
(
log2
)
logic
.
Loginfo
(
log2
,
_log_pre_yuqibi
)
}
}
logic
.
Loginfo
(
"统计逾期笔数率完成"
,
_log_pre_yuqibi
)
return
}
...
...
@@ -108,3 +213,4 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
internal/logic/common.go
View file @
933b00df
...
...
@@ -52,6 +52,15 @@ func MyFloat64(str string) float64 {
res
,
_
:=
strconv
.
ParseFloat
(
str
,
64
)
return
float64
(
res
)
}
////////////类型转换(数字转字符串)/////////////////////
func
MyFloat64ToStr
(
numb
float64
)
string
{
return
strconv
.
FormatFloat
(
numb
,
'f'
,
6
,
64
)
}
func
MyInt64ToStr
(
numb
int64
)
string
{
return
strconv
.
FormatInt
(
numb
,
10
)
}
//////////// Date/Time Functions ////////////
// Time time()
...
...
internal/logic/mylog.go
View file @
933b00df
...
...
@@ -4,6 +4,7 @@ import (
"io"
"os"
"time"
"fmt"
)
func
check
(
e
error
)
{
...
...
@@ -27,10 +28,10 @@ func checkFileIsExist(filename string) bool {
@param file_pre 附加文件前缀
eg: logic.Loginfo("逾期统计开始","_yuqilv_");
*/
func
Loginfo
(
writeString
string
,
file_pre
string
)
{
func
Loginfo
(
writeString
string
,
log_
file_pre
string
)
{
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
date2
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
var
filename
=
"./logs/"
+
date
+
file_pre
+
".txt"
var
filename
=
"./logs/"
+
date
+
log_
file_pre
+
".txt"
var
f
*
os
.
File
var
err1
error
...
...
@@ -40,8 +41,8 @@ func Loginfo(writeString string,file_pre string) {
f
,
err1
=
os
.
Create
(
filename
)
//创建文件
}
check
(
err1
)
io
.
WriteString
(
f
,
"
\r\n
---
"
+
date2
+
"----"
+
writeString
)
//写入文件(字符串)
_
,
err
:=
io
.
WriteString
(
f
,
"
\r\n
"
+
date2
+
"----"
+
writeString
)
//写入文件(字符串)
fmt
.
Print
(
err
)
}
/**
...
...
internal/service/dong_service.go
View file @
933b00df
...
...
@@ -5,12 +5,15 @@ package service
import
(
"context"
"fmt"
)
//计算逾期率
func
(
s
*
Service
)
CountYuqi
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
res
[]
map
[
string
]
interface
{},
err
error
)
{
res
,
err
=
s
.
dao
.
CountYuqi
(
ctx
,
project_id
,
erp_company_code
)
fmt
.
Print
(
err
)
func
(
s
*
Service
)
CountYuqiRate
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
res
[]
map
[
string
]
interface
{},
err
error
)
{
res
,
err
=
s
.
dao
.
CountYuqiRate
(
ctx
,
project_id
,
erp_company_code
)
return
}
//计算逾期笔数率
func
(
s
*
Service
)
CountYuqiBi
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
res
[]
map
[
string
]
interface
{},
err
error
)
{
res
,
err
=
s
.
dao
.
CountYuqiBi
(
ctx
,
project_id
,
erp_company_code
)
return
}
\ No newline at end of file
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