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
7297a67d
authored
Nov 27, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
00c363b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
24 deletions
internal/dao/yuqi_dao.go
internal/model/scores.go
internal/dao/yuqi_dao.go
View file @
7297a67d
...
...
@@ -11,25 +11,30 @@ import (
//"strconv"
"os"
//"strconv"
"time"
// "time"
"kaopu-server/internal/model"
"strconv"
)
const
(
_sql1
=
"select
* from lie_model where project_id=%s limit 1
"
//查询项目配置
_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 "
//查询公司所有信息
_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 "
//查询统计项目梯度详情
_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" //计算结果
)
//计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id_c
int
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
fmt
.
Print
(
strconv
.
ParseFloat
(
"1.112"
,
10
))
var
(
yuqilv
,
weight
,
ladder_range_min
,
ladder_range_max
,
final_score
,
scores_float
float64
//计算逾期率
score_one
string
;
//分数
)
//查询逾期率项目配置
sql_str1
:=
fmt
.
Sprintf
(
_sql1
,
strconv
.
Itoa
(
project_id_c
))
yuqilv_project
,
err
:=
d
.
QueryOne
(
ctx
,
1
,
sql_str1
)
var
weight
float64
weight
,
_
=
strconv
.
ParseFloat
(
yuqilv_project
[
"weight"
],
64
)
//查询逾期率项目详情
...
...
@@ -37,7 +42,6 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int) (r []map[string]in
modelItems
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
sql_str4
)
fmt
.
Print
(
sql_str4
,
modelItems
)
//查询当前申请的所有公司
company_info
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
_sql2
);
if
err
!=
nil
{
...
...
@@ -45,16 +49,12 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int) (r []map[string]in
return
}
var
yuqilv
,
ladder_range_min
,
ladder_range_max
,
final_score
,
scores_float
float64
//计算逾期率
var
scores
,
now_time
string
;
//分数
now_time
=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
for
_
,
v
:=
range
company_info
{
//循环当前公司,计算各个公司逾期率
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
)
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"
]
+
"逾期金额率为空,跳过"
)
continue
...
...
@@ -67,16 +67,37 @@ func (d *dao) CountYuqi(ctx context.Context,project_id_c int) (r []map[string]in
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
s
=
y
[
"score"
]
//得到的分数
score
_one
=
y
[
"score"
]
//得到的分数
}
}
//拼接最终得分
scores_float
,
_
=
strconv
.
ParseFloat
(
scores
,
64
)
final_score
=
weight
*
0.01
*
scores_float
str2
:=
fmt
.
Sprintf
(
"%8.7f"
,
final_score
)
var
temp_str
string
=
"(2,"
+
yuqilv_project
[
"pid"
]
+
","
+
yuqilv_project
[
"id"
]
+
","
+
v
[
"id"
]
+
","
+
scores
+
","
+
scores
+
","
+
yuqilv_project
[
"weight"
]
+
","
+
str2
+
","
++
","
++
")"
;
_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"
+
temp_str
scores_float
,
_
=
strconv
.
ParseFloat
(
score_one
,
64
)
final_score
=
weight
*
0.01
*
scores_float
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);
fmt
.
Print
(
scores
)
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
)
...
...
internal/model/scores.go
View file @
7297a67d
...
...
@@ -7,10 +7,10 @@ type Scores struct {
Type
int8
`json:"type"`
ProjectPid
int8
`json:"project_pid"`
ProjectId
int8
`json:"project_id"`
TotalScore
float
32
`json:"total_score"`
CurrentScore
float
32
`json:"current_score"`
Weight
float
32
`json:"weight"`
FinalScore
float
32
`json:"final_score"`
TotalScore
float
64
`json:"total_score"`
CurrentScore
float
64
`json:"current_score"`
Weight
float
64
`json:"weight"`
FinalScore
float
64
`json:"final_score"`
ComCreditsId
int64
`json:"com_credits_id"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
...
...
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