Commit 6395abcf by huangchengyi

1.0

parent f3bfe591
......@@ -22,9 +22,7 @@ func main() {
if err := paladin.Init(); err != nil {
panic(err)
}
model_dong := dao.Model_dong
mod_name := dao.Model_dong[mod]
mod_name_log := dao.Model_dong_log[mod]
model_dong := dao.Model_dong //所有动态模型算法列表
_ ,ok := model_dong[mod]
if !ok {
......@@ -44,7 +42,8 @@ func main() {
for k,_ := range model_dong{
// 开启协程
wg.Add(1)
go func(k int,ctx context.Context) {
go func(k int,ctx context.Context,mod_name string,mod_name_log string) {
fmt.Println("--开始协程:"+strconv.Itoa(k))
logic.Loginfo("统计开始--"+mod_name,mod_name_log);
......@@ -55,7 +54,7 @@ func main() {
logic.Loginfo("统计结束--"+mod_name,mod_name_log);
defer wg.Add(-1)
}(k,ctx)
}(k,ctx,dao.Model_dong[k],dao.Model_dong_log[k])
}
wg.Wait()
......
......@@ -37,10 +37,14 @@ 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)//计算逾期率
DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (zhi float64,fen float64,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) //计算逾期笔数率
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 退货率
//---动态结束
}
)
......
......@@ -21,31 +21,26 @@ var Model_dong = map[int]string{
36:"发生逾期笔数率",
37:"平均逾期支付时间(天)",
38:"平均付款时间(天)",
39:"正常收款笔数率",
40:"近6个月账期变化率",
41:"交货及时率",
42:"退货率",
43:"近6个月逾期变化率",
44:"近6个月参保人数变化率",
39:"正常收款金额率",
40:"正常收款笔数率",
41:"近6个月账期变化率",
42:"交货及时率",
43:"退货率",
44:"近6个月逾期变化率",
45:"近6个月参保人数变化率",
}
//动态模型对应的日志文件名称
var Model_dong_log = map[int]string{
35:"_yuqilv",
36:"_yuqibi",
37:"",
38:"",
39:"",
40:"",
41:"",
42:"",
43:"",
44:"",
}
//动态模型对应梯度单位
var Model_dong_unit = map[int]float64{
35: 0.01, //百分比 等于乘以 0.01
36: 0.01,
35:"_yuqi_rate",
36:"_yuqi_bi",
37:"_yuqi_div_day",
38:"_div_pay_day",
39:"_normal_pay_rate",
40:"_normal_pay_bi",
41:"_six_month",
42:"_in_time_rate",
43:"_return_rate",
44:"_shebao_rate",
}
......@@ -94,10 +89,22 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
if v["erp_company_code"] != "" {
//调用公共动态算法去查对应得分
switch project_id{
case 35:
zhi,score_one,err = d.DongYuqiRate(ctx,v,modelItems,project_id)
case 36:
zhi,score_one,err = d.DongYuqiRate(ctx,v,modelItems,project_id)
case 35: //逾期金额率
zhi,score_one,_ = d.DongYuqiRate(ctx,v,modelItems,project_id)
case 36: //发生逾期笔数率
zhi,score_one,_ = d.DongYuqiBi(ctx,v,modelItems,project_id)
case 37: //平均逾期支付时间
zhi,score_one,_ = d.DongYuqiDivDay(ctx,v,modelItems,project_id)
case 38: //平均付款时间
zhi,score_one,_ = d.DongDivPayDay(ctx,v,modelItems,project_id)
case 39: //正常收款金额率
zhi,score_one,_ = d.DongNormalPayRate(ctx,v,modelItems,project_id)
case 40: //正常收款笔数率
zhi,score_one,_ = d.DongNormalPayBi(ctx,v,modelItems,project_id)
case 42: //交货及时率
zhi,score_one,_ = d.DongInTimeRate(ctx,v,modelItems,project_id)
case 43: //退货率
zhi,score_one,_ = d.DongReturnRate(ctx,v,modelItems,project_id)
default:
continue;
}
......@@ -106,9 +113,7 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
fmt.Print(mod_name+"不存在对应梯度,erp_company_code:"+v["erp_company_code"]+" zhi:"+logic.MyFloat64ToStr(zhi)+"\r\n")
continue;
}
//拼接最终得分,权重*单位*分数
final_score = weight*Model_dong_unit[project_id]*score_one
//计算得到的分数插入分数明细表
var scores model.Scores //插入分数结构体
scores.Type=2;
scores.ProjectPid = logic.MyInt8(yuqilv_project["pid"]);
......@@ -116,7 +121,7 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
scores.TotalScore = score_one;
scores.CurrentScore = score_one;
scores.Weight= weight;
scores.FinalScore = final_score;
scores.FinalScore = weight*score_one; //权重乘以单位
scores.ComCreditsId = logic.MyInt64(v["id"]);
insertid,err := d.InsertScores(ctx,scores)
......@@ -125,7 +130,7 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
fmt.Print("错误:"+err.Error(),insertid)
}
log1 := "统计"+mod_name+"成功--公司编码:"+v["erp_company_code"]+"计算得分:"+logic.MyFloat64ToStr(score_one)+" 最终得分:"+logic.MyFloat64ToStr(final_score);
log1 := "统计"+mod_name+"成功--公司编码:"+v["erp_company_code"]+"计算得分:"+logic.MyFloat64ToStr(weight*score_one)+" 最终得分:"+logic.MyFloat64ToStr(final_score);
fmt.Print(log1)
logic.Loginfo(log1,log_pre)
}
......
......@@ -10,15 +10,23 @@ import (
const (
_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'" //发生逾期笔数
_sql5 = "select count(1) yuqibi from lie_basic_detail where delay_day>0 and erp_company_code='%s'" //发生逾期总笔数
_sql6 = "select count(1) allbi from lie_basic_detail where return_amount>0 and erp_company_code='%s'" //收款总笔数
_sql8 = "select sum(delay_day) sum_delay_day from lie_basic_detail where delay_day>0 and erp_company_code='%s'" //每笔逾期账款的逾期时间合计
_sql9 = "select sum(delay_day) sum_zhang from lie_basic_detail where erp_company_code='%s'" //每笔付款账期合计 应收日期在1/1-1/31的支付天数合计
_sql10 = "select sum(return_amount) sum_rongcha_huan from lie_basic_detail where delay_day<0 and erp_company_code='%s'" //容差范围内的收款(还款)金额 应收日期在1/1-1/31且逾期支付天数<容差值(目前为0)的下单金额合计
_sql11 = "select count(1) sum_rongcha_bi from lie_basic_detail where delay_day<0 and erp_company_code='%s'" //完成容差范围内收款的笔数 应收日期在1/1-1/31且0<逾期支付天数<容差值(目前为0)的下单订单数
_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的下单总金额合计
)
/*
@param zhi 对应梯度 率 或天
@param fen 分数,最终对应哪个梯度得分
*/
//计算逾期金额率:延期支付时间超过平均账期的金额/收款总额:
//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) {
var (
......@@ -51,7 +59,7 @@ func (d *dao) DongYuqiRate(ctx context.Context,y map[string]string,modelItems []
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) {
var (
score_one float64 =0; //分数
......@@ -65,7 +73,7 @@ func (d *dao) DongYuqiBi(ctx context.Context,y map[string]string,modelItems []ma
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
}
//查询逾期笔数
//收款总笔数
allbi,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql6,y["erp_company_code"]))
birate := logic.MyFloat64(yuqibi["yuqibi"])/logic.MyFloat64(allbi["allbi"])
......@@ -83,6 +91,233 @@ func (d *dao) DongYuqiBi(ctx context.Context,y map[string]string,modelItems []ma
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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//每笔逾期账款的逾期时间合计
yuqibi,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql8,y["erp_company_code"]))
if yuqibi["sum_delay_day"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"每笔逾期账款的逾期时间合计为0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//发生逾期总笔数
allbi,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql5,y["erp_company_code"]))
rate_res := logic.MyFloat64(yuqibi["sum_delay_day"])/logic.MyFloat64(allbi["allbi"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = 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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//每笔付款账期合计
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql9,y["erp_company_code"]))
if c1["sum_zhang"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"每笔付款账期合计0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//收款总笔数
c2,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql6,y["erp_company_code"]))
if c2["allbi"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"每笔付款账期合计0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
rate_res := logic.MyFloat64(c1["sum_zhang"])/logic.MyFloat64(c2["allbi"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = 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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//容差范围内的收款(还款)金额
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql10,y["erp_company_code"]))
if c1["sum_rongcha_huan"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"容差范围内的收款(还款)金额0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//收款金额
c2,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql15,y["erp_company_code"]))
if c2["sum_shou"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"收款总金额合计0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
rate_res := logic.MyFloat64(c1["sum_rongcha_huan"])/logic.MyFloat64(c2["sum_shou"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = 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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//完成容差范围内收款的笔数
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql11,y["erp_company_code"]))
if c1["sum_rongcha_bi"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"完成容差范围内收款的笔数0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//收款总笔数
c2,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql6,y["erp_company_code"]))
if c2["allbi"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"收款总笔数0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
rate_res := logic.MyFloat64(c1["sum_rongcha_bi"])/logic.MyFloat64(c2["allbi"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = 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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//按期交货总金额
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql10,y["erp_company_code"]))
if c1["sum_rongcha_huan"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"按期交货总金额0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//下单总金额
c2,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql12,y["erp_company_code"]))
if c2["sum_jiaohuo"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"下单总金额0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
rate_res := logic.MyFloat64(c1["sum_rongcha_huan"])/logic.MyFloat64(c2["sum_jiaohuo"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = 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) {
var (
score_one float64 =0; //分数
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
)
//退货总金额
c1,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql13,y["erp_company_code"]))
if c1["sum_tuihuo"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"按期交货总金额0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
//出库总金额
c2,_ := d.QueryOne(ctx,2,fmt.Sprintf(_sql14,y["erp_company_code"]))
if c2["sum_chuhuo"] == "0" { //没有结果
log1 := "公司编码:"+y["erp_company_code"]+"出库总金额0,跳过";
fmt.Print(log1)
logic.Loginfo("统计--"+mod_name+log1,log_pre)
return
}
rate_res := logic.MyFloat64(c1["sum_tuihuo"])/logic.MyFloat64(c2["sum_chuhuo"])
//计算分数
for _,y := range modelItems{
ladder_range_min := logic.MyFloat64(y["ladder_range_min"])
ladder_range_max := logic.MyFloat64(y["ladder_range_max"])
if (ladder_range_min <= rate_res && rate_res < ladder_range_max ) {
score_one = logic.MyFloat64(y["score"]) //得到的分数
}
}
zhi = rate_res
fen = score_one
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