Commit a24626cc by Joneq

去除map没有重新赋值的错误

parent 2ddaa705
...@@ -4,11 +4,7 @@ package main ...@@ -4,11 +4,7 @@ package main
//加分项30分) //加分项30分)
func AddScore() { func AddScore() {
IndustryReputation()
OperatingRate()
DownstreamCustomerType()
NumberOfGuarantors()
Collateral()
} }
//业界口碑(2分)) //业界口碑(2分))
......
...@@ -22,6 +22,7 @@ func CompanyInfo() { ...@@ -22,6 +22,7 @@ func CompanyInfo() {
sumScore float32 = 0 sumScore float32 = 0
joinNum float32 = 0 joinNum float32 = 0
) )
//查找出所有不是0的分值 //查找出所有不是0的分值
for i :=0;i < len(totalScore) ; i++ { for i :=0;i < len(totalScore) ; i++ {
if totalScore[i] != 0 { if totalScore[i] != 0 {
...@@ -29,12 +30,13 @@ func CompanyInfo() { ...@@ -29,12 +30,13 @@ func CompanyInfo() {
sumScore += totalScore[i] * 0.5 sumScore += totalScore[i] * 0.5
} }
} }
//经过权重计算之后的总分值 //经过权重计算之后的总分值
sumScore = sumScore / joinNum sumScore = sumScore / joinNum
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = sumScore,sumScore,sumScore insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = sumScore,sumScore,sumScore
insertScoreMsg.Weight = 50 insertScoreMsg.Weight = 50
setInserScoreChanFooter(1,0,1) setInsertScoreChanFooter(1,0,1)
} }
...@@ -44,7 +46,7 @@ func EstablishmentTime() { ...@@ -44,7 +46,7 @@ func EstablishmentTime() {
establishment_time := stringTurnInt64(companyBasicInfo["establishment_time"]) establishment_time := stringTurnInt64(companyBasicInfo["establishment_time"])
diffTime := getTimeStamp() - establishment_time diffTime := getTimeStamp() - establishment_time
//年以上有分 //年以上有分
if diffTime > (3600 * 24 * 365 * 5) { if diffTime > (3600 * 24 * 365 * 5) {
currentScore = 1 currentScore = 1
} else { } else {
...@@ -56,7 +58,7 @@ func EstablishmentTime() { ...@@ -56,7 +58,7 @@ func EstablishmentTime() {
//设置分数 //设置分数
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = currentScore,currentScore,currentScore insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = currentScore,currentScore,currentScore
insertScoreMsg.Weight = 50 insertScoreMsg.Weight = 50
setInserScoreChanFooter(1,1,8) setInsertScoreChanFooter(1,1,8)
} }
...@@ -78,7 +80,7 @@ func CompanyNature() { ...@@ -78,7 +80,7 @@ func CompanyNature() {
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = currentScore,currentScore,currentScore insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = currentScore,currentScore,currentScore
insertScoreMsg.Weight = 50 insertScoreMsg.Weight = 50
setInserScoreChanFooter(1,1,9) setInsertScoreChanFooter(1,1,9)
} }
//5年内法人变更次数(1分) //5年内法人变更次数(1分)
...@@ -96,7 +98,7 @@ func ChangeslegalInFiveYears() { ...@@ -96,7 +98,7 @@ func ChangeslegalInFiveYears() {
totalScore[2]= currentScore totalScore[2]= currentScore
setInserScoreChanFooter(1,1,10) setInsertScoreChanFooter(1,1,10)
} }
//注册资本(2分) //注册资本(2分)
...@@ -114,7 +116,7 @@ func RegisteredCapital() { ...@@ -114,7 +116,7 @@ func RegisteredCapital() {
totalScore[3]= currentScore totalScore[3]= currentScore
setInserScoreChanFooter(1,1,11) setInsertScoreChanFooter(1,1,11)
} }
//年纳税额(2分) //年纳税额(2分)
...@@ -131,7 +133,7 @@ func AnnualTaxRate() { ...@@ -131,7 +133,7 @@ func AnnualTaxRate() {
totalScore[4]= currentScore totalScore[4]= currentScore
setInserScoreChanFooter(1,1,12) setInsertScoreChanFooter(1,1,12)
} }
//近两年内有无诉讼(2分) //近两年内有无诉讼(2分)
...@@ -146,7 +148,7 @@ func lawsuitsInPastTwoYars() { ...@@ -146,7 +148,7 @@ func lawsuitsInPastTwoYars() {
totalScore[5]= currentScore totalScore[5]= currentScore
setInserScoreChanFooter(1,1,13) setInsertScoreChanFooter(1,1,13)
} }
//社保参保人数(1分) //社保参保人数(1分)
...@@ -162,7 +164,7 @@ func NumberOfSocial() { ...@@ -162,7 +164,7 @@ func NumberOfSocial() {
totalScore[6]= currentScore totalScore[6]= currentScore
setInserScoreChanFooter(1,1,14) setInsertScoreChanFooter(1,1,14)
} }
......
package main package main
var(
e_currentScore float32
e_totalScore [2]float32
)
//企业征信(10分) //企业征信(10分)
func EnterPriseCredit() { func EnterPriseCredit() {
var(
sumScore float32 = 0
joinNum float32 = 0
)
IsEnterpriseOverdueWhether() IsEnterpriseOverdueWhether()
IsHistoryOverdue() IsHistoryOverdue()
//查找出所有不是0的分值
for i :=0;i < len(e_totalScore) ; i++ {
if e_totalScore[i] != 0 {
joinNum += 1
sumScore += e_totalScore[i] * 0.5
}
}
//经过权重计算之后的总分值
sumScore = sumScore / joinNum
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = sumScore,sumScore,sumScore
insertScoreMsg.Weight = 50
setInsertScoreChanFooter(1,0,2)
} }
//企业有无负债(5分) //企业有无负债(5分)
func IsEnterpriseOverdueWhether() { func IsEnterpriseOverdueWhether() {
company_has_liabilities := stringTurnInt64(companySoreFields["company_has_liabilities"])
if company_has_liabilities == 1 {
e_currentScore = 0
}else{
e_currentScore = 5
}
e_totalScore[0]= e_currentScore
//设置分数
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = e_currentScore,e_currentScore,e_currentScore
insertScoreMsg.Weight = 50
setInsertScoreChanFooter(1,2,15)
} }
//历史有无逾期(5分) //历史有无逾期(5分)
func IsHistoryOverdue() { func IsHistoryOverdue() {
history_overdue := stringTurnInt64(companySoreFields["history_overdue"])
if history_overdue == 1 {
e_currentScore = 0
}else{
e_currentScore = 5
}
e_totalScore[1]= e_currentScore
//设置分数
insertScoreMsg.FinalScore ,insertScoreMsg.TotalScore,insertScoreMsg.CurrentScore = e_currentScore,e_currentScore,e_currentScore
insertScoreMsg.Weight = 50
setInsertScoreChanFooter(1,2,16)
} }
\ No newline at end of file
...@@ -24,6 +24,10 @@ var ( ...@@ -24,6 +24,10 @@ var (
insertScoreMsg model.Scores insertScoreMsg model.Scores
//公司的详细数据 //公司的详细数据
companyBasicInfo map[string]string companyBasicInfo map[string]string
//公司的逾期数据
companySoreFields map[string]string
//公司的逾期数据
companyAddSore map[string]string
//设置等待 //设置等待
wg sync.WaitGroup wg sync.WaitGroup
) )
...@@ -40,20 +44,23 @@ func main() { ...@@ -40,20 +44,23 @@ func main() {
go insertRecord() go insertRecord()
svc := service.New() svc := service.New()
ctx := context.Background() c := context.Background()
//调用服务获取公司信息,然后进行全局赋值 //调用服务获取公司信息,然后进行全局赋值
companyData,_ = svc.GetCompanyCresitsList(ctx) companyData,_ = svc.GetCompanyCresitsList(c)
setLog("companyData",companyData)
for _,v :=range companyData{ for _,v :=range companyData{
insertScoreMsg.ComCreditsId = stringTurnInt64(v["id"]) insertScoreMsg.ComCreditsId = stringTurnInt64(v["id"])
companyBasicInfo,_ = svc.GetCompanyBaseInfoByCid(ctx,insertScoreMsg.ComCreditsId)
CompanyInfo() CompanyInfo()
EnterPriseCredit() EnterPriseCredit()
//AddScore()
//HistoryBussiness() //HistoryBussiness()
//PersonalCredit() //PersonalCredit()
//AddScore()
} }
//赋值完关闭通道 //赋值完关闭通道
...@@ -71,9 +78,14 @@ func getConfig() { ...@@ -71,9 +78,14 @@ func getConfig() {
panic(err) panic(err)
} }
//初始化日志目录 //初始化日志目录
setLog("kaopuserver start",0)
}
func setLog(k string,v interface{}){
//初始化日志目录
log.Init(&log.Config{Dir: "logs"}) log.Init(&log.Config{Dir: "logs"})
defer log.Close() defer log.Close()
log.Info("caipu-server start") log.Info(k,v)
} }
...@@ -81,25 +93,31 @@ func getConfig() { ...@@ -81,25 +93,31 @@ func getConfig() {
func insertRecord() { func insertRecord() {
ctx := context.Background() ctx := context.Background()
for insertScoreMsg := range socreRecordChan{ for insertScoreMsgRecord := range socreRecordChan{
//声明service层 //声明service层
connect := dao.New() connect := dao.New()
//插入数据 //插入数据
insertId,err := connect.InsertScores(ctx,insertScoreMsg) insertId,err := connect.InsertScores(ctx,insertScoreMsgRecord)
fmt.Print(err) fmt.Print(err)
fmt.Print(insertId) fmt.Print(insertId)
} }
defer wg.Done() defer wg.Done()
} }
//设置插入的分数头 //设置插入的分数头
func setInserScoreChanFooter(_typy,project_pid,project_id int8) { func setInsertScoreChanFooter(_typy,project_pid,project_id int8) {
insertScoreMsg.Type,insertScoreMsg.ProjectPid,insertScoreMsg.ProjectId = _typy,project_pid,project_id insertScoreMsg.Type,insertScoreMsg.ProjectPid,insertScoreMsg.ProjectId = _typy,project_pid,project_id
socreRecordChan <- insertScoreMsg socreRecordChan <- insertScoreMsg
} }
//获取详细的计算基本数据
func getCompanyRunInfo(c context.Context) {
//声明service层
connect := dao.New()
companyBasicInfo,_ = connect.GetCompanyBaseInfoByCid(c,insertScoreMsg.ComCreditsId)
companySoreFields,_ = connect.GetCompanyScoreFieldsByCid(c,insertScoreMsg.ComCreditsId)
}
func getTimeStamp()(timestamp int64) { func getTimeStamp()(timestamp int64) {
return time.Now().Unix() return time.Now().Unix()
} }
......
package dao
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/bilibili/kratos/pkg/database/sql"
)
//通过UID获取用户加分信息
func (d *dao) GeAddScoresByCid(c context.Context, companyId int64) (res map[string]string, err error) {
var (
rows *sql.Rows
)
if rows, err = d.db.Query(c, "select "+ SqlField + " from lie_add_scores where com_credits_id = ?",companyId); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
if err != nil{
fmt.Println("select fail,err:",err)
return
}
twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{
res = v
break
}
return
}
\ No newline at end of file
...@@ -27,7 +27,6 @@ func GetAllParam(rows *sql.Rows)(res []map[string]string, err error) { ...@@ -27,7 +27,6 @@ func GetAllParam(rows *sql.Rows)(res []map[string]string, err error) {
scans[i] = &vals[i] scans[i] = &vals[i]
} }
row := make(map[string]string)
for rows.Next(){ for rows.Next(){
err = rows.Scan(scans...) err = rows.Scan(scans...)
...@@ -36,6 +35,8 @@ func GetAllParam(rows *sql.Rows)(res []map[string]string, err error) { ...@@ -36,6 +35,8 @@ func GetAllParam(rows *sql.Rows)(res []map[string]string, err error) {
return return
} }
row := make(map[string]string)
for k,v:=range vals{ for k,v:=range vals{
key := cols[k] key := cols[k]
row[key] = string(v) row[key] = string(v)
......
package dao
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/bilibili/kratos/pkg/database/sql"
)
//通过UID获取用户信息
func (d *dao) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (res map[string]string, err error) {
var (
rows *sql.Rows
)
if rows, err = d.db.Query(c, "select "+ SqlField + " from lie_credit_score_fields where com_credits_id = ?",companyId); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
if err != nil{
fmt.Println("select fail,err:",err)
return
}
twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{
res = v
break
}
return
}
\ No newline at end of file
...@@ -24,6 +24,7 @@ type ( ...@@ -24,6 +24,7 @@ type (
GetCompanyCresitsList(ctx context.Context) (r []map[string]string, err error) GetCompanyCresitsList(ctx context.Context) (r []map[string]string, err error)
InsertScores(ctx context.Context, score model.Scores) (insertId int64, err error) InsertScores(ctx context.Context, score model.Scores) (insertId int64, err error)
GetCompanyBaseInfoByCid(c context.Context, companyId int64) (r map[string]string, err error) GetCompanyBaseInfoByCid(c context.Context, companyId int64) (r map[string]string, err error)
GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (r map[string]string, err error)
//---静态结束 //---静态结束
CountYuqi(ctx context.Context,project_id int) (r []map[string]interface{},err error) //计算逾期 CountYuqi(ctx context.Context,project_id int) (r []map[string]interface{},err error) //计算逾期
......
package model
/*CREATE TABLE `lie_add_score` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '加分项id',
`com_credits_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联信用分id',
`project_name` varchar(50) NOT NULL DEFAULT '' COMMENT '项目名',
`info` varchar(150) NOT NULL DEFAULT '' COMMENT '信息备注',
`current_score` decimal(6,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '得分 没有进行权重运算的得分',
`weight` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '权重',
`final_score` decimal(6,2) NOT NULL DEFAULT '0.00' COMMENT '最终得分-终评分 进行了权重运算后的得分',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '1正常 0删除',
`create_time` int(11) unsigned NOT NULL DEFAULT '0',
`update_time` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `company_code` (`com_credits_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COMMENT='加分项表';*/
\ No newline at end of file
package model
//CREATE TABLE `lie_credit_score_fields` (
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
//`company_has_liabilities` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '企业有无负债 1有 0没有',
//`history overdue` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '历史有无逾期 1有 0无',
//`age` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '年龄',
//`marital_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '婚姻状况 1是 0否',
//`account_ratio` decimal(6,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '违约账户比 50.23',
//`guaranty` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '对外担保 1有 0没有',
//`two_years_th_days_overdue_times` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '近2年内最大逾期金额',
//`two_years_max_overdue_amount` decimal(14,4) NOT NULL,
//`is_exist_now_overdue` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1 是 0否',
//`presence_of_mortgage` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '有无房贷 1有 0没有',
//`two_months_credit_view_nums` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '近两个月征信查询次数',
//`credit_card_total` decimal(14,4) unsigned NOT NULL DEFAULT '0.0000' COMMENT '信用卡总额度',
//`maximum_credit_card_limit` decimal(14,4) unsigned NOT NULL DEFAULT '0.0000' COMMENT '单张信用卡最高额度',
//`com_credits_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联公司信用id',
//`type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1个人 2企业',
//`create_time` int(11) unsigned NOT NULL DEFAULT '0',
//`update_time` int(11) unsigned NOT NULL DEFAULT '0',
//PRIMARY KEY (`id`)
//) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='征信相关评分字段表';
\ No newline at end of file
...@@ -79,5 +79,14 @@ func (s *Service) GetCompanyBaseInfoByCid(c context.Context, companyId int64) (r ...@@ -79,5 +79,14 @@ func (s *Service) GetCompanyBaseInfoByCid(c context.Context, companyId int64) (r
return return
} }
// 获取公司用户列表
func (s *Service) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (res map[string]string, err error) {
//调用DB方法,获取会员数据
res, err = s.dao.GetCompanyScoreFieldsByCid(c,companyId)
fmt.Print(err)
return
}
//----------静态结束 //----------静态结束
\ No newline at end of file
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
[2019/11/21 17:22:25.088] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.004363403s [2019/11/21 17:22:25.088] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.004363403s
[2019/11/21 17:23:29.451] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.003427317s [2019/11/21 17:23:29.451] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.003427317s
[2019/11/21 17:24:18.153] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.004311142s [2019/11/21 17:24:18.153] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Query query(SELECT * FROM lie_com_credits ) args([]) time: 1.004311142s
[2019/11/26 14:08:41.510] [WARN] [/Users/gongyang/go/pkg/mod/github.com/bilibili/kratos@v0.3.1/pkg/database/sql/sql.go:679] sql_client slow log statement: Exec query(INSERT INTO `lie_scores` (`type`, `project_pid`, `project_id`, `total_score`, `current_score`, `weight`, `final_score`, `com_credits_id`, `create_time`)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)) args([1 2 15 5 5 50 5 5 1574748521]) time: 265.318628ms
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