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
78e1eace
authored
Nov 26, 2019
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
864da239
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
54 deletions
cmd/dong/main.go
configs/mysql.toml
internal/dao/common.go
internal/dao/dao.go
internal/dao/users.go
internal/dao/yuqi_dao.go
internal/service/dong_service.go
cmd/dong/main.go
View file @
78e1eace
...
...
@@ -14,7 +14,6 @@ import (
func
main
()
{
//获取输入参数
var
mod
int
;
flag
.
IntVar
(
&
mod
,
"m"
,
0
,
"请输入模块id"
)
// 单独计算某个模块,默认计算全部,0计算全部
...
...
@@ -54,24 +53,12 @@ func main() {
//实例化所有
}
//初始化日志目录
log
.
Init
(
&
log
.
Config
{
Dir
:
"logs"
})
defer
log
.
Close
()
log
.
Info
(
"caipu-server start"
)
//声明service层
//svc := service.New()
//ctx := context.Background()
////调用会员服务
//for{
// // svc.GetUserList(ctx)
// fmt.Println("nnii")
// fmt.Println(time.Now())
time
.
Sleep
(
time
.
Second
)
//}
}
configs/mysql.toml
View file @
78e1eace
[Liexin_credit]
addr
=
"192.168.2.232:3306"
dsn
=
"liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
readDSN
=
["liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
,"liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
]
readDSN
=
["liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"]
active
=
20
idle
=
10
idleTimeout
=
"4h"
queryTimeout
=
"200ms"
execTimeout
=
"300ms"
tranTimeout
=
"400ms"
[Liexin_credit_source]
addr
=
"192.168.2.232:3306"
dsn
=
"liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit_source?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
readDSN
=
["liexin_credit:liexin_credit#zsyM@tcp(192.168.2.232:3306)/liexin_credit_source?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"]
active
=
20
idle
=
10
idleTimeout
=
"4h"
queryTimeout
=
"200ms"
execTimeout
=
"300ms"
tranTimeout
=
"400ms"
\ No newline at end of file
internal/dao/common.go
View file @
78e1eace
...
...
@@ -2,7 +2,9 @@ package dao
import
(
"fmt"
"context"
"github.com/bilibili/kratos/pkg/database/sql"
"github.com/pkg/errors"
)
//定义一些sql执行语句
...
...
@@ -44,3 +46,63 @@ func GetAllParam(rows *sql.Rows)(res []map[string]string, err error) {
}
return
}
//封装查询(单列查询)
func
(
d
*
dao
)
QueryOne
(
ctx
context
.
Context
,
db
int
,
sql_str
string
)(
res
map
[
string
]
string
,
err
error
)
{
var
(
rows
*
sql
.
Rows
)
//fmt.Print(sql_str)
if
db
==
1
{
if
rows
,
err
=
d
.
db
.
Query
(
ctx
,
sql_str
);
err
!=
nil
{
err
=
errors
.
WithStack
(
err
)
return
}
}
else
{
if
rows
,
err
=
d
.
db2
.
Query
(
ctx
,
sql_str
);
err
!=
nil
{
err
=
errors
.
WithStack
(
err
)
return
}
}
defer
rows
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
"error1001:"
+
sql_str
,
err
)
return
}
project_rows
,
err
:=
GetAllParam
(
rows
);
if
project_rows
==
nil
{
fmt
.
Println
(
"error1002"
+
sql_str
,
err
)
return
}
for
_
,
v
:=
range
project_rows
{
res
=
v
break
}
return
}
//封装查询(多列查询)
func
(
d
*
dao
)
QueryMany
(
ctx
context
.
Context
,
db
int
,
sql_str
string
)(
res
[]
map
[
string
]
string
,
err
error
)
{
var
(
rows1
*
sql
.
Rows
)
//查询项目配置
if
rows1
,
err
=
d
.
db
.
Query
(
ctx
,
sql_str
);
err
!=
nil
{
err
=
errors
.
WithStack
(
err
)
return
}
defer
rows1
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
"error1001:"
+
sql_str
,
err
)
return
}
project_rows
,
err
:=
GetAllParam
(
rows1
);
if
err
!=
nil
{
fmt
.
Println
(
"error1002"
+
sql_str
,
err
)
return
}
res
=
project_rows
return
}
internal/dao/dao.go
View file @
78e1eace
...
...
@@ -10,6 +10,9 @@ import (
"github.com/bilibili/kratos/pkg/database/sql"
"github.com/bilibili/kratos/pkg/log"
xtime
"github.com/bilibili/kratos/pkg/time"
//"os"
//"fmt"
//"github.com/pkg/errors"
)
type
(
...
...
@@ -19,6 +22,8 @@ type (
Ping
(
ctx
context
.
Context
)
(
err
error
)
GetUserInfoByUserId
(
ctx
context
.
Context
,
user_id
int64
)
(
r
*
model
.
Users
,
err
error
)
GetUserList
(
ctx
context
.
Context
)
(
r
[]
*
model
.
Users
,
err
error
)
QueryOne
(
ctx
context
.
Context
,
db
int
,
sql_str
string
)(
res
map
[
string
]
string
,
err
error
)
//封装查询一条数据
QueryMany
(
ctx
context
.
Context
,
db
int
,
sql_str
string
)(
res
[]
map
[
string
]
string
,
err
error
)
//封装查询多条数据
//---静态开始
GetCompanyCresitsList
(
ctx
context
.
Context
)
(
r
[]
map
[
string
]
string
,
err
error
)
...
...
@@ -33,6 +38,7 @@ type (
// dao dao.
type
dao
struct
{
db
*
sql
.
DB
db2
*
sql
.
DB
redis
*
redis
.
Pool
redisExpire
int32
mc
*
memcache
.
Memcache
...
...
@@ -51,6 +57,7 @@ func New() (Dao) {
var
(
dc
struct
{
Liexin_credit
*
sql
.
Config
Liexin_credit_source
*
sql
.
Config
}
rc
struct
{
Demo
*
redis
.
Config
...
...
@@ -67,6 +74,7 @@ func New() (Dao) {
return
&
dao
{
// mysql
db
:
sql
.
NewMySQL
(
dc
.
Liexin_credit
),
db2
:
sql
.
NewMySQL
(
dc
.
Liexin_credit_source
),
// redis
redis
:
redis
.
NewPool
(
rc
.
Demo
),
redisExpire
:
int32
(
time
.
Duration
(
rc
.
DemoExpire
)
/
time
.
Second
),
...
...
@@ -109,3 +117,4 @@ func (d *dao) pingRedis(ctx context.Context) (err error) {
}
return
}
internal/dao/users.go
View file @
78e1eace
...
...
@@ -5,7 +5,6 @@ import (
"kaopu-server/internal/model"
"github.com/bilibili/kratos/pkg/database/sql"
"github.com/pkg/errors"
)
...
...
@@ -56,4 +55,4 @@ func (d *dao) GetUserList(ctx context.Context) (res []*model.Users, err error) {
err
=
rows
.
Err
()
return
}
\ No newline at end of file
}
internal/dao/yuqi_dao.go
View file @
78e1eace
...
...
@@ -3,52 +3,87 @@ package dao
import
(
"context"
"fmt"
"github.com/bilibili/kratos/pkg/database/sql"
"github.com/pkg/errors"
"strconv"
//"github.com/bilibili/kratos/pkg/database/sql"
//"github.com/pkg/errors"
//"strconv"
//"os"
//"strconv"
//"strconv"
"os"
//"strconv"
"time"
"strconv"
)
const
(
_sql1
=
"select id,project_name from lie_model where project_id=%s limit 1"
//查询项目配置
_sql2
=
"select * from lie_basic_info "
)
_sql1
=
"select * from lie_model where project_id=%s limit 1"
//查询项目配置
_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 "
//查询统计项目梯度详情
)
var
(
project_res
[]
map
[
string
]
interface
{}
)
//计算逾期分数
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id
int
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
var
(
rows
*
sql
.
Rows
)
////mod = new(model.Models)
//row = d.db.QueryRow(ctx, _sql1,project_id)
////if err = row.Scan(&mod.Id, &mod.Project_name); err != nil {
//// err = nil
//// return
////}
//project_res,_ = getAllParam(row);
//fmt.Println(project_res)
//os.Exit(1)
//查询项目配置
if
rows
,
err
=
d
.
db
.
Query
(
ctx
,
fmt
.
Sprintf
(
_sql1
,
strconv
.
Itoa
(
project_id
)));
err
!=
nil
{
err
=
errors
.
WithStack
(
err
)
return
}
defer
rows
.
Close
()
//计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
func
(
d
*
dao
)
CountYuqi
(
ctx
context
.
Context
,
project_id_c
int
)
(
r
[]
map
[
string
]
interface
{},
err
error
)
{
fmt
.
Print
(
strconv
.
ParseFloat
(
"1.112"
,
10
))
//查询逾期率项目配置
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
)
//查询逾期率项目详情
sql_str4
:=
fmt
.
Sprintf
(
_sql4
,
strconv
.
Itoa
(
project_id_c
))
modelItems
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
sql_str4
)
fmt
.
Print
(
sql_str4
,
modelItems
)
if
err
!=
nil
{
fmt
.
Println
(
"select fail,err:"
,
err
)
//查询当前申请的所有公司
company_info
,
err
:=
d
.
QueryMany
(
ctx
,
1
,
_sql2
);
if
err
!=
nil
{
fmt
.
Println
(
"
\r\n
error:1004"
,
err
)
return
}
project_res
,
_
=
getAllParam
(
rows
);
//
if
project_res
==
nil
{
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
)
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
)
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
{
scores
=
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
os
.
Exit
(
1
)
}
}
fmt
.
Println
(
project_res
)
fmt
.
Println
(
company_info
)
os
.
Exit
(
1
)
return
...
...
@@ -60,3 +95,4 @@ func (d *dao) CountYuqi(ctx context.Context,project_id int) (r []map[string]inte
internal/service/dong_service.go
View file @
78e1eace
...
...
@@ -10,8 +10,6 @@ import (
//计算逾期率
func
(
s
*
Service
)
CountYuqi
(
ctx
context
.
Context
,
project_id
int
)
(
res
[]
map
[
string
]
interface
{},
err
error
)
{
//调用DB方法,获取会员数据
res
,
err
=
s
.
dao
.
CountYuqi
(
ctx
,
project_id
)
fmt
.
Print
(
err
)
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