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
1b7cf1a2
authored
Nov 27, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
bc4969ae
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
45 deletions
cmd/dong/main.go
go.mod
internal/dao/dao.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 @
1b7cf1a2
...
...
@@ -5,17 +5,13 @@ 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"
)
func
main
()
{
logic
.
Loginfo
(
"逾期统计开始"
,
"_yuqilv_"
);
//获取输入参数
//获取输入参数s
var
mod
int
;
flag
.
IntVar
(
&
mod
,
"m"
,
0
,
"请输入模块id"
)
// 单独计算某个模块,默认计算全部,0计算全部
flag
.
Parse
()
...
...
@@ -46,19 +42,16 @@ func main() {
ctx
:=
context
.
Background
()
//上下文
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
)
//实例化所有
}
//初始化日志目录
log
.
Init
(
&
log
.
Config
{
Dir
:
"logs/"
})
defer
log
.
Close
()
log
.
Info
(
"caipu-server start"
)
}
go.mod
deleted
100644 → 0
View file @
bc4969ae
module kaopu-server
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 @
1b7cf1a2
...
...
@@ -34,7 +34,10 @@ type (
GetCompanyAddSoreByCid
(
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/yuqi_dao.go
View file @
1b7cf1a2
...
...
@@ -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
...
...
@@ -34,7 +37,6 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
//查询逾期率项目详情
sql_str4
:=
fmt
.
Sprintf
(
_sql4
,
strconv
.
Itoa
(
project_id_c
))
modelItems
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
sql_str4
)
//fmt.Print(sql_str4,modelItems)
//查询当前申请的所有公司
if
erp_company_code
==
""
{
...
...
@@ -45,7 +47,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 +56,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 +74,6 @@ 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
)
//拼接最终得分
final_score
=
weight
*
0.01
*
score_one
...
...
@@ -91,13 +91,97 @@ 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
)
}
//fmt.Print(scores,weight,final_score)
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
(
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
)
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
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:1004"
,
err
.
Error
())
logic
.
Loginfo
(
"错误"
+
err
.
Error
(),
_log_pre_yuqibi
)
return
}
os
.
Exit
(
1
)
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"
]
+
"没有预期笔数,跳过"
)
continue
}
//查询逾期笔数
allbi
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
fmt
.
Sprintf
(
_sql6
,
v
[
"erp_company_code"
]))
var
birate
float64
=
logic
.
MyFloat64
(
yuqibi
[
"yuqibi"
])
/
logic
.
MyFloat64
(
allbi
[
"allbi"
])
//查询逾期率对应分数
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"
])
//得到的分数
}
}
//拼接最终得分
final_score
=
weight
*
0.01
*
score_one
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"
]);
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
(
log1
)
logic
.
Loginfo
(
log1
,
_log_pre_yuqibi
)
}
}
logic
.
Loginfo
(
"统计逾期率完成"
,
_log_pre_yuqibi
)
return
}
...
...
@@ -108,3 +192,4 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int,erp_company_code st
internal/logic/common.go
View file @
1b7cf1a2
...
...
@@ -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 @
1b7cf1a2
...
...
@@ -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 @
1b7cf1a2
...
...
@@ -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