Commit 25f6846a by huangchengyi

1.0

parent 36582d6c
......@@ -38,14 +38,16 @@ type (
//---动态开始
DongMain(ctx context.Context,project_id int,erp_company_code string) (r []map[string]interface{},err error) //动态模型调用主函数
DongYuqiRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//1 计算逾期金额率
DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//2 发生逾期笔数率
DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//3 平均逾期支付时间
DongDivPayDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//4 平均付款时间
DongNormalPayRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//5 正常收款金额率
DongNormalPayBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//6 正常收款笔数率
DongInTimeRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//8 交货及时率
DongReturnRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,err error)//9 退货率
//1 计算逾期金额率 ,ladder_rate 计算出来的此算法对应梯度率,ladder_score 梯度对应的分数
DongYuqiRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)
DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//2 发生逾期笔数率
DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//3 平均逾期支付时间
DongDivPayDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//4 平均付款时间
DongNormalPayRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//5 正常收款金额率
DongNormalPayBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//6 正常收款笔数率
DongInTimeRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//8 交货及时率
DongReturnRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate float64,ladder_score float64,err error)//9 退货率
DongAddScore(ctx context.Context,com_credits_id int64)(affectNum int64) //统计动态分数,更新到每个公司
//---动态结束
}
)
......@@ -104,6 +106,7 @@ func (d *dao) Close() {
d.mc.Close()
d.redis.Close()
d.db.Close()
d.db2.Close()
}
// Ping ping the resource.
......
......@@ -29,6 +29,7 @@ var Model_dong = map[int]string{
43:"退货率",
44:"近6个月逾期变化率",
45:"近6个月参保人数变化率",
999:"统计动态分数",
}
//动态模型对应的日志文件名称
var Model_dong_log = map[int]string{
......@@ -48,8 +49,8 @@ var Model_dong_log = map[int]string{
func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code string) (r []map[string]interface{},err error) {
var (
zhi float64 //计算出来的各个动态分数率
score_one float64 =0; //对应梯度分数
ladder_rate float64 //计算出来的各个动态分数率
ladder_score float64 =0; //对应梯度分数
_sql2 string; //
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
......@@ -89,32 +90,36 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
return
}
for _,v := range company_info{ //循环当前公司,计算各个公司对应分数
if v["erp_company_code"] != "" {
//调用公共动态算法去查对应得分
switch project_id{
case 35: //逾期金额率
zhi,score_one,_ = d.DongYuqiRate(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongYuqiRate(ctx,v,modelItems,project_id)
case 36: //发生逾期笔数率
zhi,score_one,_ = d.DongYuqiBi(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongYuqiBi(ctx,v,modelItems,project_id)
case 37: //平均逾期支付时间
zhi,score_one,_ = d.DongYuqiDivDay(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongYuqiDivDay(ctx,v,modelItems,project_id)
case 38: //平均付款时间
zhi,score_one,_ = d.DongDivPayDay(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongDivPayDay(ctx,v,modelItems,project_id)
case 39: //正常收款金额率
zhi,score_one,_ = d.DongNormalPayRate(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongNormalPayRate(ctx,v,modelItems,project_id)
case 40: //正常收款笔数率
zhi,score_one,_ = d.DongNormalPayBi(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongNormalPayBi(ctx,v,modelItems,project_id)
case 42: //交货及时率
zhi,score_one,_ = d.DongInTimeRate(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongInTimeRate(ctx,v,modelItems,project_id)
case 43: //退货率
zhi,score_one,_ = d.DongReturnRate(ctx,v,modelItems,project_id)
ladder_rate,ladder_score,_ = d.DongReturnRate(ctx,v,modelItems,project_id)
case 999:
d.DongAddScore(ctx,logic.MyInt64(v["id"])) //总计所有分数
continue;
default:
continue;
}
if score_one == 0 {
log1 := "统计"+mod_name+"--跳过,没有分数,公司编码:"+v["erp_company_code"]+" 计算率:"+logic.MyFloat64ToStr(zhi)+"\r\n"
if ladder_score == 0 {
log1 := "统计"+mod_name+"--跳过,没有分数,公司编码:"+v["erp_company_code"]+" 计算率:"+logic.MyFloat64ToStr(ladder_rate)+"\r\n"
fmt.Print(log1)
logic.Loginfo(log1,log_pre)
continue;
......@@ -124,19 +129,20 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
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.TotalScore = ladder_score;
scores.CurrentScore = ladder_score;
scores.Weight= weight;
scores.FinalScore = weight*score_one; //权重乘以单位
scores.FinalScore = weight*ladder_score; //权重乘以单位
scores.ComCreditsId = logic.MyInt64(v["id"]);
//d := New()
insertid,err := d.InsertScores(ctx,scores)
if err != nil {
logic.Loginfo("错误:"+err.Error(),log_pre)
fmt.Print("错误:"+err.Error(),insertid)
fmt.Print("错误:"+err.Error(),insertid,ladder_rate)
}
log2 := "统计"+mod_name+"--成功,公司编码:"+v["erp_company_code"]+" 计算得分:"+logic.MyFloat64ToStr(score_one)+" 最终得分:"+logic.MyFloat64ToStr(weight*score_one);
log2 := "统计"+mod_name+"--成功,公司编码:"+v["erp_company_code"]+" 计算得分:"+logic.MyFloat64ToStr(ladder_score)+" 最终得分:"+logic.MyFloat64ToStr(weight*ladder_score);
fmt.Print(log2)
logic.Loginfo(log2,log_pre)
}
......
......@@ -19,15 +19,16 @@ const (
_sql12 = "select sum(order_amount) sum_jiaohuo from lie_basic_detail where erp_company_code='%s'" //交货总金额 退货总金额+出库总金额
_sql13 = "select abs(sum(return_amount)) sum_tuihuo from lie_basic_detail where return_amount<0 and erp_company_code='%s'" //退货总金额 下单时间在1/1-1/30且下单金额为负数的金额合计
_sql14 = "select sum(order_amount) sum_chuhuo from lie_basic_detail where order_amount>0 and erp_company_code='%s'" //出货总金额 下单时间在1/1-1/30的下单总金额合计
_sql15= "select sum(return_amount) sum_shou from lie_basic_detail where return_amount>0 and erp_company_code='%s'" //收款总额 应收日期在1/1-1/31的回款金额 下单时间在1/1-1/30的下单总金额合计
)
_sql15 = "select sum(return_amount) sum_shou from lie_basic_detail where return_amount>0 and erp_company_code='%s'" //收款总额 应收日期在1/1-1/31的回款金额 下单时间在1/1-1/30的下单总金额合计
_sql16 = "select sum(final_score) sum_dong_score from lie_scores where type=2 and com_credits_id=%s"; //总计动态信用分
)
/*
@param zhi 对应梯度 率 或天
@param fen 分数,最终对应哪个梯度得分
@param ladder_score 对应梯度 率 或天
@param ladder_score 分数,最终对应哪个梯度得分
*/
//1 计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
func (d *dao) DongYuqiRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongYuqiRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
......@@ -46,13 +47,13 @@ func (d *dao) DongYuqiRate(ctx context.Context,y map[string]string,modelItems []
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = yuqilv
fen = score_one
ladder_rate = yuqilv
ladder_score = score_one
return
}
//2 发生逾期笔数率: 发生逾期笔数/收款总笔数
func (d *dao) DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
)
......@@ -74,13 +75,13 @@ func (d *dao) DongYuqiBi(ctx context.Context,y map[string]string,modelItems []ma
}
}
zhi = birate
fen = score_one
ladder_rate = birate
ladder_score = score_one
return
}
//3 平均逾期支付时间(天): 每笔逾期账款的逾期时间合计/发生逾期总笔数
func (d *dao) DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
)
......@@ -102,13 +103,13 @@ func (d *dao) DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//4 平均付款时间(天): 每笔付款账期合计/收款总笔数
func (d *dao) DongDivPayDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongDivPayDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
......@@ -141,13 +142,13 @@ func (d *dao) DongDivPayDay(ctx context.Context,y map[string]string,modelItems [
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//5 正常收款金额率: 容差范围内的收款(还款)金额/收款总金额
func (d *dao) DongNormalPayRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongNormalPayRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
......@@ -180,13 +181,13 @@ func (d *dao) DongNormalPayRate(ctx context.Context,y map[string]string,modelIte
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//6 正常收款笔数率:完成容差范围内收款的笔数/收款总笔数
func (d *dao) DongNormalPayBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongNormalPayBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
......@@ -219,13 +220,13 @@ func (d *dao) DongNormalPayBi(ctx context.Context,y map[string]string,modelItems
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//8 交货及时率: 按期交货总金额/交货总金额(下单总金额) PS按期交货:逾期交付天数<0
func (d *dao) DongInTimeRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongInTimeRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
......@@ -258,13 +259,13 @@ func (d *dao) DongInTimeRate(ctx context.Context,y map[string]string,modelItems
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//9 退货率 : 退货总金额/出库总金额(下单总金额) PS退货总金额金额为负数的订单
func (d *dao) DongReturnRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (zhi float64,fen float64,err error) {
func (d *dao) DongReturnRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int) (ladder_rate float64,ladder_score float64,err error) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
......@@ -297,12 +298,35 @@ func (d *dao) DongReturnRate(ctx context.Context,y map[string]string,modelItems
}
}
zhi = rate_res
fen = score_one
ladder_rate = rate_res
ladder_score = score_one
return
}
//累计公司动态信用分
func (d *dao) DongAddScore(ctx context.Context,com_credits_id int64)(affectNum int64) {
var(
execSql string
sum_dong_score float64 //动态模型总分
)
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql16,com_credits_id))
if c1["sum_dong_score"] == "0" || c1["sum_dong_score"] == "" { //没有结果
sum_dong_score = 0
}else{
sum_dong_score = logic.MyFloat64(c1["sum_dong_score"])
}
execSql = "update `lie_com_credits` set `dynamic_credit_score` = ? where id = ? "
row,err := d.db.Exec(ctx,execSql,sum_dong_score,com_credits_id)
if err != nil {
logic.Loginfo("更新动态总分出错"+err.Error(),"sum_dong")
}
affectNum,_ = row.RowsAffected()
defer d.db.Close()
return
}
......
......@@ -2,6 +2,7 @@ package dao
import (
"context"
"fmt"
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/model"
"time"
......@@ -17,8 +18,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 {
......@@ -42,6 +43,6 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
}
insertId = affectNum
defer d.db.Close()
//defer d.db.Close()
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment