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
592de3c0
authored
Nov 27, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
b7d67be7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
52 deletions
cmd/dong/main.go
internal/dao/dao.go
internal/dao/scores.go
internal/dao/yuqi_dao.go
internal/logic/common.go
internal/service/dong_service.go
cmd/dong/main.go
View file @
592de3c0
...
...
@@ -47,7 +47,7 @@ func main() {
switch
mod
{
case
35
:
//计算逾期率
fmt
.
Println
(
"计算逾期率开始:"
+
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
))
svc
.
CountYuqi
(
ctx
,
mod
);
svc
.
CountYuqi
(
ctx
,
mod
,
""
);
default
:
fmt
.
Println
(
mod
)
//实例化所有
...
...
internal/dao/dao.go
View file @
592de3c0
...
...
@@ -34,7 +34,7 @@ type (
GetCompanyAddSoreByCid
(
c
context
.
Context
,
companyId
int64
)
(
r
[]
map
[
string
]
string
,
err
error
)
//---静态结束
CountYuqi
(
ctx
context
.
Context
,
project_id
int
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
//计算逾期
CountYuqi
(
ctx
context
.
Context
,
project_id
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
//计算逾期
}
)
...
...
internal/dao/scores.go
View file @
592de3c0
...
...
@@ -22,4 +22,4 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
row
.
LastInsertId
()
defer
d
.
db
.
Close
()
return
}
\ No newline at end of file
}
internal/dao/yuqi_dao.go
View file @
592de3c0
...
...
@@ -3,46 +3,46 @@ package dao
import
(
"context"
"fmt"
//"github.com/bilibili/kratos/pkg/database/sql"
//"github.com/pkg/errors"
//"strconv"
//"os"
//"strconv"
//"strconv"
"os"
//"strconv"
// "time"
"kaopu-server/internal/model"
"kaopu-server/internal/logic"
"strconv"
)
const
(
_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
=
"select 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 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 project_id,ladder_range_min,ladder_range_max from lie_model_items where project_id=%s "
//查询统计项目梯度详情
//_sql5 = "INSERT INTO lie_scores(type,project_pid,project_id,com_credits_id,total_score,current_score,weight,final_score,create_time,update_time) VALUES %s" //计算结果
_sql4
=
"select * from lie_model_items where project_id=%s "
//查询统计项目梯度详情
)
//计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id_c
int
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id_c
int
,
erp_company_code
string
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
var
(
yuqilv
,
weight
,
ladder_range_min
,
ladder_range_max
,
final_score
,
scores_float
float64
//计算逾期率
score_one
string
;
//分数
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
)
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
)
//
fmt.Print(sql_str4,modelItems)
//查询当前申请的所有公司
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
)
...
...
@@ -53,60 +53,51 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int) (r []map[string]in
if
v
[
"erp_company_code"
]
!=
""
{
//查询逾期率
sql3
:=
fmt
.
Sprintf
(
_sql3
,
v
[
"erp_company_code"
])
fmt
.
Print
(
"
\r\n
查询sql:"
+
sql3
)
//
fmt.Print("\r\n查询sql:"+sql3)
oneyu
,
_
:=
d
.
QueryOne
(
ctx
,
2
,
sql3
)
if
oneyu
==
nil
{
//没有结果
fmt
.
Print
(
"
\r\n
公司编码:"
+
v
[
"erp_company_code"
]
+
"逾期金额率为空,跳过"
)
continue
}
fmt
.
Print
(
"
\r\n
公司编码:"
+
v
[
"erp_company_code"
]
+
"逾期金额率为:"
+
oneyu
[
"yuqilv"
])
//查询逾期率对应分数
yuqilv
,
_
=
strconv
.
ParseFloat
(
oneyu
[
"yuqilv"
],
64
)
yuqilv
,
_
:
=
strconv
.
ParseFloat
(
oneyu
[
"yuqilv"
],
64
)
for
_
,
y
:=
range
modelItems
{
ladder_range_min
,
_
=
strconv
.
ParseFloat
(
y
[
"ladder_range_min"
],
64
)
ladder_range_max
,
_
=
strconv
.
ParseFloat
(
y
[
"ladder_range_max"
],
64
)
if
ladder_range_max
<
yuqilv
&&
ladder_range_min
>=
yuqilv
{
score_one
=
y
[
"score"
]
//得到的分数
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
<=
yuqilv
&&
yuqilv
<
ladder_range_max
)
{
score_one
=
logic
.
MyFloat64
(
y
[
"score"
])
//得到的分数
}
}
fmt
.
Print
(
"
\r\n\r\n
score_one:"
,
score_one
)
//拼接最终得分
scores_float
,
_
=
strconv
.
ParseFloat
(
score_one
,
64
)
final_score
=
weight
*
0.01
*
scores_float
final_score
=
weight
*
0.01
*
score_one
var
scores
model
.
Scores
//插入分数结构体
scores
.
Type
=
2
;
//scores.ProjectPid = int8(ss
);
//scores.ProjectId ,_ = strconv.ParseInt(yuqilv_project["id"],10,8
);
//scores.TotalScore,_ = strconv.ParseFloat(score_one,32)
;
//scores.CurrentScore,_ = strconv.ParseFloat(score_one,32)
;
//
scores.Weight= weight;
//scores.FinalScore = fmt.Sprintf("%8.7f", final_score)
;
//scores.ComCreditsId,_ = strconv.ParseInt(v["id"],10,64
);
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
(
scores
)
fmt
.
Print
(
"
\r\n\r\n
结构体:"
,
score_one
)
insertid
,
err
:=
d
.
InsertScores
(
ctx
,
scores
)
if
err
!=
nil
{
fmt
.
Print
(
err
,
insertid
)
}
fmt
.
Print
(
scores
,
weight
,
final_score
)
//
//fmt.Print(yuqilv_project)
//var temp_str string = "(2,"+yuqilv_project["pid"]+","+yuqilv_project["id"]+","+v["id"]+","+scores+","+scores+","+yuqilv_project["weight"]+","+str2+","+now_time+","+now_time+")";
//sql5 := fmt.Sprintf(_sql5,temp_str)
//if _, err = d.db.Exec(ctx, sql5); err != nil {
// fmt.Print("\r\n\r\n插入最终分数失败:"+sql5,err)
//}
os
.
Exit
(
1
)
//fmt.Print(scores,weight,final_score)
}
}
fmt
.
Println
(
company_info
)
os
.
Exit
(
1
)
return
}
...
...
internal/logic/common.go
View file @
592de3c0
...
...
@@ -31,10 +31,31 @@ import (
"unicode"
"unicode/utf8"
)
////////////类型转换(字符串转数字)/////////////////////
func
MyInt8
(
str
string
)
int8
{
res
,
_
:=
strconv
.
ParseInt
(
str
,
10
,
64
)
return
int8
(
res
)
}
func
MyInt16
(
str
string
)
int16
{
res
,
_
:=
strconv
.
ParseInt
(
str
,
10
,
64
)
return
int16
(
res
)
}
func
MyInt64
(
str
string
)
int64
{
res
,
_
:=
strconv
.
ParseInt
(
str
,
10
,
64
)
return
int64
(
res
)
}
func
MyFloat32
(
str
string
)
float32
{
res
,
_
:=
strconv
.
ParseFloat
(
str
,
64
)
return
float32
(
res
)
}
func
MyFloat64
(
str
string
)
float64
{
res
,
_
:=
strconv
.
ParseFloat
(
str
,
64
)
return
float64
(
res
)
}
//////////// Date/Time Functions ////////////
// Time time()
func
g
etTimeStamp
()(
timestamp
int64
)
{
func
G
etTimeStamp
()(
timestamp
int64
)
{
return
time
.
Now
()
.
Unix
()
}
...
...
internal/service/dong_service.go
View file @
592de3c0
...
...
@@ -9,8 +9,8 @@ import (
)
//计算逾期率
func
(
s
*
Service
)
CountYuqi
(
ctx
context
.
Context
,
project_id
int
)
(
res
[]
map
[
string
]
interface
{},
err
error
)
{
res
,
err
=
s
.
dao
.
CountYuqi
(
ctx
,
project_id
)
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
)
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