Commit 1ab3390f by huangchengyi

1.0

parent a6fcca99
......@@ -43,16 +43,9 @@ type (
//---动态开始
DongMain(ctx context.Context,project_id int,erp_company_code string) (r []map[string]interface{},err error) //动态模型调用主函数
//1 计算逾期金额率 ,ladder_rate 计算出来的此算法对应梯度率,ladder_score 梯度对应的分数
DongYuqiRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)
DongYuqiBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//2 发生逾期笔数率
DongYuqiDivDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//3 平均逾期支付时间
DongDivPayDay(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//4 平均付款时间
DongNormalPayRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//5 正常收款金额率
DongNormalPayBi(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//6 正常收款笔数率
DongInTimeRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//8 交货及时率
DongReturnRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int ) (ladder_rate string,ladder_score float64,err error)//9 退货率
DongAddScore(ctx context.Context,com_credits_id int64)(affectNum int64) //统计动态分数,更新到每个公司
InsertScores2(ctx context.Context, score model.Scores,month_six_zi int64) (insertId int64, err error) //插入分数
DongRate(ctx context.Context,y map[string]string,modelItems []map[string]string,project_id int,month_six string ) (ladder_rate float64,ladder_score float64,remark string,err error)
DongAddScore(ctx context.Context,com_credits_id int64,month_six_zi string )(affectNum int64) //统计动态分数,更新到每个公司
//---动态结束
}
)
......
......@@ -6,13 +6,16 @@ import (
"kaopu-server/internal/logic"
"kaopu-server/internal/model"
"strconv"
"strings"
"time"
)
//存放动态模型所有常量
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_1 = "select id,erp_company_code,company_name from lie_com_credits where status=5 order by id asc " //查询公司所有信息
_sql2_1 = "select id,erp_company_code,company_name from lie_com_credits where status>=5 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 * from lie_model_items where project_id=%s " //查询统计项目梯度详情
)
//项目对应的id
......@@ -29,6 +32,7 @@ var Model_dong = map[int]string{
43:"退货率",
44:"近6个月逾期变化率",
45:"近6个月参保人数变化率",
48:"账期使用程度倍数",
999:"累计动态分数",
-1:"队列监听",
}
......@@ -50,9 +54,12 @@ 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 (
weight float64 //权重
ladder_rate string //计算出来的各个动态分数率
ladder_score float64 =0; //对应梯度分数
_sql2 string; //查询公司信息sql
month_six string //拼接6个月字符串,sql用
month_six_zi string //拼接6个月字符串,日期自动用
ladder_rate float64 //计算出来的各个动态分数率
ladder_score float64 =0 //对应梯度分数
_sql2 string //查询公司信息sql
remark string //备注
mod_name string = Model_dong[project_id] //统计动态模型名称
log_pre string = Model_dong_log[project_id] //日志文件名称
modelItem map[string]string //配置主表
......@@ -70,7 +77,7 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
weight,_ = strconv.ParseFloat(modelItem["weight"],64)
//查询逾期率项目详情
sql_str4 := fmt.Sprintf(_sql4,strconv.Itoa(project_id))
sql_str4 := fmt.Sprintf(_sql3,strconv.Itoa(project_id))
modelItems,_ = d.QueryMany(ctx,1,sql_str4)
if modelItems == nil {
logic.LogWrite("不存在该项目配置详情lie_model_items,project_id:"+strconv.Itoa(project_id),log_pre,1)
......@@ -86,44 +93,52 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
}
company_info,err := d.QueryMany(ctx,1,_sql2);
if err != nil {
logic.LogWrite("错误"+err.Error(),log_pre,1)
return
}
nowTime := time.Now()
getTime := nowTime.AddDate(0, -6, 0) //年,月,日 获取前六个月的时间
year := logic.MyInt64(getTime.Format("2006"))
month := logic.MyInt64(getTime.Format("01"))
month_six_zi = getTime.Format("2006")+getTime.Format("01")+time.Now().AddDate(0, -1, 0).Format("01") //20190612 代表 2019年6 至 12 月
p := 0
for i := month; i <= 12; i++ {
if p == 6 {
break;
}
if i <10 {
month_six += logic.MyInt64ToStr(year)+"0"+logic.MyInt64ToStr(i)+","
}else{
month_six += logic.MyInt64ToStr(year)+logic.MyInt64ToStr(i)+","
}
if i == 12 { //1月
year = year+1
i = 1
}
p +=1
}
month_six = strings.TrimRight(month_six,",") // 六个月sql
for _,v := range company_info{ //循环当前公司,计算各个公司对应分数
if v["erp_company_code"] == "" {
continue;
}
//调用公共动态算法去查对应得分
switch project_id{
case 35: //逾期金额率
ladder_rate,ladder_score,_ = d.DongYuqiRate(ctx,v,modelItems,project_id)
case 36: //发生逾期笔数率
ladder_rate,ladder_score,_ = d.DongYuqiBi(ctx,v,modelItems,project_id)
case 37: //平均逾期支付时间
ladder_rate,ladder_score,_ = d.DongYuqiDivDay(ctx,v,modelItems,project_id)
case 38: //平均付款时间
ladder_rate,ladder_score,_ = d.DongDivPayDay(ctx,v,modelItems,project_id)
case 39: //正常收款金额率
ladder_rate,ladder_score,_ = d.DongNormalPayRate(ctx,v,modelItems,project_id)
case 40: //正常收款笔数率
ladder_rate,ladder_score,_ = d.DongNormalPayBi(ctx,v,modelItems,project_id)
case 42: //交货及时率
ladder_rate,ladder_score,_ = d.DongInTimeRate(ctx,v,modelItems,project_id)
case 43: //退货率
ladder_rate,ladder_score,_ = d.DongReturnRate(ctx,v,modelItems,project_id)
case 999:
d.DongAddScore(ctx,logic.MyInt64(v["id"])) //总计所有分数
if project_id == 999 { //总计所有分数
d.DongAddScore(ctx,logic.MyInt64(v["id"]),month_six_zi) //总计所有分数
continue
default:
continue;
}else{
ladder_rate,ladder_score,remark,_ = d.DongRate(ctx,v,modelItems,project_id,month_six) //调用公共动态算法去查对应得分
}
if ladder_score == 0 {
logic.LogWrite("统计"+mod_name+"--没有梯度对应分数,公司编码:"+v["erp_company_code"]+" 计算公式:"+ladder_rate,log_pre,1)
continue;
}
//if ladder_score == 0 {
// logic.LogWrite("统计"+mod_name+"--没有梯度对应分数,公司编码:"+v["erp_company_code"]+" 计算公式:"+remark,log_pre,1)
// continue;
//}
//计算得到的分数插入分数明细表
var scores model.Scores //插入分数结构体
ProjectPid := logic.MyInt8(modelItem["pid"])
......@@ -137,16 +152,21 @@ func (d *dao) DongMain(ctx context.Context,project_id int,erp_company_code strin
scores.Weight= weight;
scores.FinalScore = weight*ladder_score; //权重乘以单位
scores.ComCreditsId = logic.MyInt64(v["id"]);
scores.Month = logic.MyInt64(month_six_zi);
scores.Current_rate = ladder_rate
scores.Remark = remark
//fmt.Print(scores)
//os.Exit(1)
//d := New()
insertid,err := d.InsertScores(ctx,scores)
insertid,err := d.InsertScores2(ctx,scores,logic.MyInt64(month_six_zi))
if err != nil {
logic.Loginfo("错误:"+err.Error(),log_pre)
fmt.Print("错误:"+err.Error(),insertid,ladder_rate)
}
//日志
logic.LogWrite("统计"+mod_name+"--成功,公司编码:"+v["erp_company_code"]+" 计算公式:"+ladder_rate+" 梯度得分:"+logic.MyFloat64ToStr(ladder_score)+" 权重:"+logic.MyFloat64ToStr(weight)+" 最终得分:"+logic.MyFloat64ToStr(weight*ladder_score),log_pre,1)
logic.LogWrite("统计"+mod_name+"--成功,公司编码:"+v["erp_company_code"]+" 计算公式:"+remark+" 梯度得分:"+logic.MyFloat64ToStr(ladder_score)+" 权重:"+logic.MyFloat64ToStr(weight)+" 最终得分:"+logic.MyFloat64ToStr(weight*ladder_score),log_pre,1)
}
return
......
......@@ -48,3 +48,46 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
return
}
//增加或者修改记录(动态模型专用)
func (d *dao) InsertScores2(ctx context.Context,score model.Scores,month_six_zi int64) (insertId int64,err error) {
//defer d.db.Close()
var(
exitId int
execSql string
affectNum int64
)
//ss := fmt.Sprintf("select id from lie_scores where `type` = %d and project_pid = %d and project_id = %d and com_credits_id = %d limit 0,1", score.Type,score.ProjectPid,score.ProjectId,score.ComCreditsId)
//print(ss)
err = d.db.QueryRow(ctx,"select id from lie_scores where `type` = ? and project_pid = ? and project_id = ? and com_credits_id = ? and month= ? limit 0,1", score.Type,score.ProjectPid,score.ProjectId,score.ComCreditsId,month_six_zi).Scan(&exitId)
if err != nil {
//fmt.Print(err)
//sql := fmt.Sprintf("select id from lie_scores where `type` = %d and project_pid = %d and project_id = %d and com_credits_id = %d and month= %d limit 0,1", score.Type,score.ProjectPid,score.ProjectId,score.ComCreditsId,month_six_zi);
//fmt.Print("查询失败:"+sql)
//os.Exit(1)
}
if exitId == 0 {
execSql = "INSERT INTO `lie_scores` (`type`, `project_pid`, `project_id`, `total_score`, `current_score`, `weight`, `final_score`, `com_credits_id`, `create_time`,`current_rate`,`month`,`remark`)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?)"
row,err := d.db.Exec(ctx,execSql,score.Type,score.ProjectPid,score.ProjectId,score.TotalScore,score.CurrentScore,score.Weight,score.FinalScore,score.ComCreditsId,time.Now().Unix(),score.Current_rate,score.Month,score.Remark)
if err != nil {
log.Error("InsertScoresdb.DemoExec.Exec(%s) error(%v)", execSql, err)
}else{
affectNum,_ = row.LastInsertId()
}
}else{
execSql = "update `lie_scores` set `type` = ?, `project_pid` = ?, `project_id` = ?, `total_score` = ?, `current_score` = ?, `weight` = ?, `final_score` = ?, `update_time` = ?, `current_rate` = ?, `remark` = ? where `type` = ? and project_pid = ? and project_id = ? and com_credits_id = ? and month = ?"
row,err := d.db.Exec(ctx,execSql,score.Type,score.ProjectPid,score.ProjectId,score.TotalScore,score.CurrentScore,score.Weight,score.FinalScore,time.Now().Unix(), score.Current_rate,score.Remark,score.Type,score.ProjectPid,score.ProjectId,score.ComCreditsId,month_six_zi)
if err != nil {
log.Error("updateScoresdb.DemoExec.Exec(%s) error(%v)", execSql, err)
}else{
affectNum,_ = row.RowsAffected()
}
}
insertId = affectNum
return
}
\ No newline at end of file
......@@ -14,6 +14,9 @@ type Scores struct {
ComCreditsId int64 `json:"com_credits_id"`
CreateTime int64 `json:"create_time"`
UpdateTime int64 `json:"update_time"`
Month int64 `json:"month"`
Current_rate float64 `json:"current_rate"`
Remark string `json:"remark"`
}
/*CREATE TABLE `lie_scores` (
......
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