Commit dfa8dfa2 by huangchengyi

Merge branch 'dev' of http://119.23.72.7/sunlong_v5/kaopu-server into dev

parents 1ab3390f f540ba69
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"kaopu-server/internal/dao" "kaopu-server/internal/dao"
"kaopu-server/internal/service"
"strconv" "strconv"
"time" "time"
) )
...@@ -13,28 +12,18 @@ import ( ...@@ -13,28 +12,18 @@ import (
func SetSumScore(c context.Context) { func SetSumScore(c context.Context) {
com_credits.Id = insertScoreMsg.ComCreditsId com_credits.Id = insertScoreMsg.ComCreditsId
com_credits.StaticCreditScore = CompanyInfo()+ AddScore()+ EnterPriseCredit()+ HistoryBussiness() + PersonalCredit() com_credits.StaticCreditScore = CompanyInfo()+ AddScore()+ EnterPriseCredit()+ HistoryBussiness() + PersonalCredit()
connect := dao.New() _,err := svclient.UpdateStaticSumScores(c,com_credits)
_,err := connect.UpdateStaticSumScores(c,com_credits)
fmt.Print(err) fmt.Print(err)
} }
//协程增加分值记录 //协程增加分值记录
func InsertRecord(c context.Context) { func InsertRecord() {
for insertScoreMsgRecord := range socreRecordChan{ for insertScoreMsgRecord := range socreRecordChan{
//声明service层 insertId,err := svclient.InsertScores(conclient,insertScoreMsgRecord)
svc := service.New()
//CurrentScore64 := float64(insertScoreMsgRecord.CurrentScore)
//插入数据
//if !math.IsNaN(CurrentScore64) && CurrentScore64 != 0 {
//}
//svc.InsertScores(c,insertScoreMsgRecord)
insertId,err := svc.InsertScores(c,insertScoreMsgRecord)
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
//fmt.Print(err)
fmt.Print(insertId) fmt.Print(insertId)
} }
defer wg.Done() defer wg.Done()
...@@ -47,13 +36,10 @@ func SetInsertScoreChanFooter(_typy,project_pid,project_id int8) { ...@@ -47,13 +36,10 @@ func SetInsertScoreChanFooter(_typy,project_pid,project_id int8) {
} }
//获取详细的计算基本数据 //获取详细的计算基本数据
func GetCompanyRunInfo(c context.Context) { func GetCompanyRunInfo() {
//声明service层 companyBasicInfo,_ = svclient.GetCompanyBaseInfoByCid(conclient,insertScoreMsg.ComCreditsId)
connect := dao.New() companySoreFields,_ = svclient.GetCompanyScoreFieldsByCid(conclient,insertScoreMsg.ComCreditsId)
companyBasicInfo,_ = connect.GetCompanyBaseInfoByCid(c,insertScoreMsg.ComCreditsId) companyAddScore,_ = svclient.GetCompanyAddSoreByCid(conclient,insertScoreMsg.ComCreditsId)
companySoreFields,_ = connect.GetCompanyScoreFieldsByCid(c,insertScoreMsg.ComCreditsId)
companyAddScore,_ = connect.GetCompanyAddSoreByCid(c,insertScoreMsg.ComCreditsId)
basicInfo,_ = connect.GetBasicInfoByCid(c,insertScoreMsg.ComCreditsId)
} }
func GetTimeStamp()(timestamp int64) { func GetTimeStamp()(timestamp int64) {
......
...@@ -5,10 +5,12 @@ import ( ...@@ -5,10 +5,12 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq" "github.com/ichunt2019/go-msgserver/utils/rabbitmq"
"kaopu-server/internal/logic"
"kaopu-server/internal/model" "kaopu-server/internal/model"
"kaopu-server/internal/service" "kaopu-server/internal/service"
"os"
"sync" "sync"
"time" "time"
) )
...@@ -33,14 +35,20 @@ var ( ...@@ -33,14 +35,20 @@ var (
companyAddScore []map[string]string companyAddScore []map[string]string
//设置等待 //设置等待
wg sync.WaitGroup wg sync.WaitGroup
//运行方式 //设置svclient
runtype string svclient *service.Service
//content Client
conclient context.Context
) )
type RecvPro struct { type RecvPro struct {
} }
type Rabitmq struct {
Dsn string //rabitmq 配置1
}
func (t *RecvPro) FailAction([]byte) error { func (t *RecvPro) FailAction([]byte) error {
fmt.Print(1) fmt.Print(1)
panic("implement me") panic("implement me")
...@@ -53,32 +61,51 @@ type RabbitMsg struct { ...@@ -53,32 +61,51 @@ type RabbitMsg struct {
//获取配置参数
func GetConfig() {
//获取输入参数
flag.Parse()
if err := paladin.Init(); err != nil {
panic(err)
}
//初始化日志目录
SetLog("kaopuserver start",0)
}
func SetLog(k string,v interface{}){
//初始化日志目录
log.Init(&log.Config{Dir: "logs"})
defer log.Close()
log.Info(k,v)
}
func main() { func main() {
//获取config //获取config
logic.GetConfig() GetConfig()
svclient = service.New()
flag.StringVar(&runtype, "runtype", "one", "default config path") conclient = context.Background()
if runtype == "one" { if os.Args[2] == "one" {
//设置协程数量 //设置协程数量
wg.Add(1) wg.Add(1)
c := context.Background() go InsertRecord()
go InsertRecord(c)
//调用服务获取公司信息,然后进行全局赋值 //调用服务获取公司信息,然后进行全局赋值
svc := service.New() companyData,_ = svclient.GetCompanyCresitsList(conclient)
companyData,_ = svc.GetCompanyCresitsList(c)
for _,v :=range companyData{ for _,v :=range companyData{
insertScoreMsg.ComCreditsId = StringTurnInt64(v["id"]) insertScoreMsg.ComCreditsId = StringTurnInt64(v["id"])
GetCompanyRunInfo(c) GetCompanyRunInfo()
SetSumScore(c) basicInfo,_ = svclient.GetBasicInfoByCid(conclient,v["erp_company_code"])
SetSumScore(conclient)
//break //break
} }
...@@ -88,14 +115,22 @@ func main() { ...@@ -88,14 +115,22 @@ func main() {
wg.Wait() wg.Wait()
}else{ }else{
t := &RecvPro{} t := &RecvPro{}
var (
dc struct {
Dsn1 *Rabitmq // rab配置1
}
)
paladin.Get("rabitmq.toml").UnmarshalTOML(&dc) //读取配置
queueExchange := &rabbitmq.QueueExchange{ queueExchange := &rabbitmq.QueueExchange{
"fengkong_static_count", "fengkong_static_count",
"fengkong_static_count", "fengkong_static_count",
"fengkong_exchange", "fengkong_exchange",
"direct", "direct",
"amqp://guest:guest@192.168.2.232:5672/", "amqp://"+dc.Dsn1.Dsn+"/",
} }
for{ for{
...@@ -127,12 +162,13 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -127,12 +162,13 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//设置协程数量 //设置协程数量
wg.Add(1) wg.Add(1)
c := context.Background() conclient = context.Background()
go InsertRecord(c) go InsertRecord()
insertScoreMsg.ComCreditsId = StringTurnInt64(rbm.ComCreditsId) insertScoreMsg.ComCreditsId = StringTurnInt64(rbm.ComCreditsId)
GetCompanyRunInfo(c) GetCompanyRunInfo()
SetSumScore(c) basicInfo,_ = svclient.GetBasicInfoByCid(conclient,rbm.ErpCompanyCode)
SetSumScore(conclient)
//赋值完关闭通道 //赋值完关闭通道
close(socreRecordChan) close(socreRecordChan)
......
...@@ -18,7 +18,7 @@ func (d *dao) GetCompanyAddSoreByCid(c context.Context, companyId int64) (res [] ...@@ -18,7 +18,7 @@ func (d *dao) GetCompanyAddSoreByCid(c context.Context, companyId int64) (res []
return return
} }
defer d.db.Close() defer rows.Close()
if err != nil{ if err != nil{
fmt.Println("select fail,err:",err) fmt.Println("select fail,err:",err)
......
...@@ -8,17 +8,17 @@ import ( ...@@ -8,17 +8,17 @@ import (
) )
//通过UID获取用户信息 //通过UID获取用户信息
func (d *dao) GetBasicInfoByCid(c context.Context, companyId int64) (res map[string]string, err error) { func (d *dao) GetBasicInfoByCid(c context.Context, erp_company_code string) (res map[string]string, err error) {
var ( var (
rows *sql.Rows rows *sql.Rows
) )
if rows, err = d.db.Query(c, "select "+ SqlField + " from lie_basic_info where com_credits_id = ?",companyId); err != nil { if rows, err = d.db.Query(c, "select "+ SqlField + " from lie_basic_info where erp_company_code = ?",erp_company_code); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
return return
} }
defer d.db.Close() defer rows.Close()
if err != nil{ if err != nil{
fmt.Println("select fail,err:",err) fmt.Println("select fail,err:",err)
......
...@@ -50,12 +50,13 @@ func (d *dao)UpdateCompanyBaseInfoForTyc(c context.Context,updateInfo map[string ...@@ -50,12 +50,13 @@ func (d *dao)UpdateCompanyBaseInfoForTyc(c context.Context,updateInfo map[string
var( var(
execSql string execSql string
) )
execSql = "update `lie_com_basicinfos` set `customer_property` = ?, `establishment_time` = ?, `five_legal_change` = ?, `registered_capital` = ?, `social_security_participants` = ?, `two_years_no_lawsuit` = ? , `tyc_select_num` = ? , `tianyancha_json` = ? where com_credits_id = ? " execSql = "update `lie_com_basicinfos` set `customer_property` = ?, `establishment_time` = ?, `five_legal_change` = ?, `registered_capital` = ?, `social_security_participants` = ?, `two_years_no_lawsuit` = ? , `tyc_select_num` = ? , `tianyancha_json` = ?, `com_address` = ?, `legal_representative` = ? where com_credits_id = ? "
row,err := d.db.Exec(c,execSql,updateInfo["customer_property"],updateInfo["establishment_time"],updateInfo["five_legal_change"],updateInfo["registered_capital"],updateInfo["social_security_participants"],updateInfo["two_years_no_lawsuit"],updateInfo["tyc_select_num"],updateInfo["tianyancha_json"],updateInfo["com_credits_id"]) row,err := d.db.Exec(c,execSql,updateInfo["customer_property"],updateInfo["establishment_time"],updateInfo["five_legal_change"],updateInfo["registered_capital"],updateInfo["social_security_participants"],updateInfo["two_years_no_lawsuit"],updateInfo["tyc_select_num"],updateInfo["tianyancha_json"],updateInfo["com_address"],updateInfo["legal_representative"],updateInfo["com_credits_id"])
if err != nil { if err != nil {
log.Error("updateScoresdb.DemoExec.Exec(%s) error(%v)", execSql, err) log.Error("updateScoresdb.DemoExec.Exec(%s) error(%v)", execSql, err)
} }
affectNum,err := row.RowsAffected() affectNum,err := row.RowsAffected()
return affectNum return affectNum
......
...@@ -20,7 +20,7 @@ func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []map[string]strin ...@@ -20,7 +20,7 @@ func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []map[string]strin
return return
} }
defer d.db.Close() defer rows.Close()
if err != nil{ if err != nil{
fmt.Println("select fail,err:",err) fmt.Println("select fail,err:",err)
...@@ -47,8 +47,6 @@ func (d *dao) UpdateStaticSumScores(ctx context.Context,com_credits model.ComCre ...@@ -47,8 +47,6 @@ func (d *dao) UpdateStaticSumScores(ctx context.Context,com_credits model.ComCre
row.RowsAffected() row.RowsAffected()
defer d.db.Close()
return return
} }
...@@ -83,6 +81,8 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)( ...@@ -83,6 +81,8 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)(
err = errors.WithStack(err) err = errors.WithStack(err)
return return
} }
defer rows.Close()
if err != nil{ if err != nil{
...@@ -90,6 +90,7 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)( ...@@ -90,6 +90,7 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)(
return return
} }
twoMap,err := GetAllParam(rows) twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{ for _,v:=range twoMap{
...@@ -130,6 +131,7 @@ func (d *dao)GetGrade(ctx context.Context,sumScore float64)(res map[string]strin ...@@ -130,6 +131,7 @@ func (d *dao)GetGrade(ctx context.Context,sumScore float64)(res map[string]strin
return return
} }
twoMap,err := GetAllParam(rows) twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{ for _,v:=range twoMap{
......
...@@ -34,7 +34,6 @@ func (d *dao) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (re ...@@ -34,7 +34,6 @@ func (d *dao) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (re
res = v res = v
break break
} }
defer d.db.Close()
return return
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ type ( ...@@ -30,7 +30,7 @@ type (
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) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (r map[string]string, err error)
GetBasicInfoByCid(c context.Context, companyId int64) (r map[string]string, err error) GetBasicInfoByCid(c context.Context, erpCompanyCode string) (r map[string]string, err error)
GetCompanyAddSoreByCid(c context.Context, companyId int64) (r []map[string]string, err error) GetCompanyAddSoreByCid(c context.Context, companyId int64) (r []map[string]string, err error)
GetCompanyModelByProjectid(c context.Context, companyId int64) (r map[string]string, err error) GetCompanyModelByProjectid(c context.Context, companyId int64) (r map[string]string, err error)
GetModelTopsetByProjectId(c context.Context, companyId int64) (r map[string]string, err error) GetModelTopsetByProjectId(c context.Context, companyId int64) (r map[string]string, err error)
......
...@@ -33,9 +33,6 @@ func (d *dao) GetCompanyModelItemsByProjectid(c context.Context, project_id int6 ...@@ -33,9 +33,6 @@ func (d *dao) GetCompanyModelItemsByProjectid(c context.Context, project_id int6
res = v res = v
break break
} }
defer d.db.Close()
fmt.Print(res)
return return
} }
......
...@@ -32,7 +32,6 @@ func (d *dao) GetModelTopsetByProjectId(c context.Context, projectId int64) (res ...@@ -32,7 +32,6 @@ func (d *dao) GetModelTopsetByProjectId(c context.Context, projectId int64) (res
res = v res = v
break break
} }
defer d.db.Close()
return return
} }
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/bilibili/kratos/pkg/log" "github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/model" "kaopu-server/internal/model"
"time" "time"
"github.com/bilibili/kratos/pkg/database/sql"
) )
//增加或者修改记录 //增加或者修改记录
...@@ -15,13 +16,25 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int ...@@ -15,13 +16,25 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
exitId int exitId int
execSql string execSql string
affectNum int64 affectNum int64
rows *sql.Rows
) )
//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) rows,err = d.db.Query(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)
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 { defer rows.Close()
fmt.Print(err)
fmt.Print("save list fail") if err != nil{
fmt.Println("select fail,err:",err)
return
}
twoMap,err := GetAllParam(rows)
exitId = 0
for _,v:=range twoMap{
fmt.Print(v)
exitId = 1
break
} }
if exitId == 0 { if exitId == 0 {
......
...@@ -10,10 +10,7 @@ import ( ...@@ -10,10 +10,7 @@ import (
"encoding/csv" "encoding/csv"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"hash/crc32" "hash/crc32"
"html" "html"
"io" "io"
...@@ -2239,24 +2236,6 @@ func Ternary(condition bool, trueVal, falseVal interface{}) interface{} { ...@@ -2239,24 +2236,6 @@ func Ternary(condition bool, trueVal, falseVal interface{}) interface{} {
} }
//获取配置参数
func GetConfig() {
//获取输入参数
flag.Parse()
if err := paladin.Init(); err != nil {
panic(err)
}
//初始化日志目录
SetLog("kaopuserver start",0)
}
func SetLog(k string,v interface{}){
//初始化日志目录
log.Init(&log.Config{Dir: "logs"})
defer log.Close()
log.Info(k,v)
}
func StringTurnInt64(val string) (int64) { func StringTurnInt64(val string) (int64) {
intval,_ := strconv.ParseInt(val, 10, 64) intval,_ := strconv.ParseInt(val, 10, 64)
return intval return intval
......
package logic
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const APIDOMAIN string = "http://api.liexin.com/msg/sendMessageByAuto"
func sendMessage(mobile , content string){
timeNow := time.Now().Second()
requestContent,_ := json.Marshal(map[string]string{"content":content})
requestTel,_ := json.Marshal([]string{mobile})
requestbody,err := json.Marshal(map[string]map[string]string{
"form_params" :{
"data" : string(requestContent),
"touser" :string(requestTel),
"keyword" : "crm_notify_kefu",
"k1" : Int64TurnString(int64(timeNow)),
"k2" : Md5(Md5(Int64TurnString(int64(timeNow)))+APIMD5STR),
"is_ignore" : "true",
},
})
if err != nil {
fmt.Print(err)
}
resp,err := http.Post(APIDOMAIN,"application/json",bytes.NewBuffer(requestbody))
defer resp.Body.Close()
}
...@@ -14,6 +14,8 @@ type TianYanChaCompanyInfo struct { ...@@ -14,6 +14,8 @@ type TianYanChaCompanyInfo struct {
CompanyOrgType string `json:"companyOrgType"` CompanyOrgType string `json:"companyOrgType"`
SocialStaffNum float64 `json:"socialStaffNum"` SocialStaffNum float64 `json:"socialStaffNum"`
RegCapital string `json:"regCapital"` RegCapital string `json:"regCapital"`
LegalPersonName string `json:"legalPersonName"`
RegLocation string `json:"regLocation"`
} }
type ResultStruct struct { type ResultStruct struct {
...@@ -46,6 +48,8 @@ func HttpGet(companyName string)(returnDatas map[string]string) { ...@@ -46,6 +48,8 @@ func HttpGet(companyName string)(returnDatas map[string]string) {
returnData := make(map[string]string) returnData := make(map[string]string)
//成立时间 //成立时间
returnData["establishment_time"] = strconv.FormatFloat((companyTycInfo.Result.EstiblishTime/1000), 'f', -1, 64) returnData["establishment_time"] = strconv.FormatFloat((companyTycInfo.Result.EstiblishTime/1000), 'f', -1, 64)
returnData["legal_representative"] = companyTycInfo.Result.LegalPersonName
returnData["com_address"] = companyTycInfo.Result.RegLocation
returnData["tianyancha_json"] = string(respBody) returnData["tianyancha_json"] = string(respBody)
//公司性质 //公司性质
var companyOrgType string var companyOrgType string
......
...@@ -89,10 +89,10 @@ func (s *Service) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) ...@@ -89,10 +89,10 @@ func (s *Service) GetCompanyScoreFieldsByCid(c context.Context, companyId int64)
} }
// 获取公司历史信息 // 获取公司历史信息
func (s *Service) GetBasicInfoByCid(c context.Context, companyId int64) (res map[string]string, err error) { func (s *Service) GetBasicInfoByCid(c context.Context, erpCompanyCode string) (res map[string]string, err error) {
//调用DB方法,获取会员数据 //调用DB方法,获取会员数据
res, err = s.dao.GetBasicInfoByCid(c,companyId) res, err = s.dao.GetBasicInfoByCid(c,erpCompanyCode)
fmt.Print(err) fmt.Print(err)
return return
} }
...@@ -130,8 +130,15 @@ func (s *Service) InsertScores(c context.Context,score model.Scores) (res int64, ...@@ -130,8 +130,15 @@ func (s *Service) InsertScores(c context.Context,score model.Scores) (res int64,
//调用DB方法,获取会员数据 //调用DB方法,获取会员数据
res, err = s.dao.InsertScores(c,score) res, err = s.dao.InsertScores(c,score)
defer s.dao.Close() fmt.Print(err)
//fmt.Print(err) return
}
func (s *Service)GetCompanyAddSoreByCid(c context.Context, companyId int64) (res []map[string]string, err error){
//调用DB方法,获取会员数据
res, err = s.dao.GetCompanyAddSoreByCid(c,companyId)
fmt.Print(err)
return 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