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 (
"context"
"fmt"
"kaopu-server/internal/dao"
"kaopu-server/internal/service"
"strconv"
"time"
)
......@@ -13,28 +12,18 @@ import (
func SetSumScore(c context.Context) {
com_credits.Id = insertScoreMsg.ComCreditsId
com_credits.StaticCreditScore = CompanyInfo()+ AddScore()+ EnterPriseCredit()+ HistoryBussiness() + PersonalCredit()
connect := dao.New()
_,err := connect.UpdateStaticSumScores(c,com_credits)
_,err := svclient.UpdateStaticSumScores(c,com_credits)
fmt.Print(err)
}
//协程增加分值记录
func InsertRecord(c context.Context) {
func InsertRecord() {
for insertScoreMsgRecord := range socreRecordChan{
//声明service层
svc := service.New()
//CurrentScore64 := float64(insertScoreMsgRecord.CurrentScore)
//插入数据
//if !math.IsNaN(CurrentScore64) && CurrentScore64 != 0 {
//}
//svc.InsertScores(c,insertScoreMsgRecord)
insertId,err := svc.InsertScores(c,insertScoreMsgRecord)
insertId,err := svclient.InsertScores(conclient,insertScoreMsgRecord)
if err != nil {
fmt.Print(err)
}
//fmt.Print(err)
fmt.Print(insertId)
}
defer wg.Done()
......@@ -47,13 +36,10 @@ func SetInsertScoreChanFooter(_typy,project_pid,project_id int8) {
}
//获取详细的计算基本数据
func GetCompanyRunInfo(c context.Context) {
//声明service层
connect := dao.New()
companyBasicInfo,_ = connect.GetCompanyBaseInfoByCid(c,insertScoreMsg.ComCreditsId)
companySoreFields,_ = connect.GetCompanyScoreFieldsByCid(c,insertScoreMsg.ComCreditsId)
companyAddScore,_ = connect.GetCompanyAddSoreByCid(c,insertScoreMsg.ComCreditsId)
basicInfo,_ = connect.GetBasicInfoByCid(c,insertScoreMsg.ComCreditsId)
func GetCompanyRunInfo() {
companyBasicInfo,_ = svclient.GetCompanyBaseInfoByCid(conclient,insertScoreMsg.ComCreditsId)
companySoreFields,_ = svclient.GetCompanyScoreFieldsByCid(conclient,insertScoreMsg.ComCreditsId)
companyAddScore,_ = svclient.GetCompanyAddSoreByCid(conclient,insertScoreMsg.ComCreditsId)
}
func GetTimeStamp()(timestamp int64) {
......
......@@ -5,10 +5,12 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq"
"kaopu-server/internal/logic"
"kaopu-server/internal/model"
"kaopu-server/internal/service"
"os"
"sync"
"time"
)
......@@ -33,14 +35,20 @@ var (
companyAddScore []map[string]string
//设置等待
wg sync.WaitGroup
//运行方式
runtype string
//设置svclient
svclient *service.Service
//content Client
conclient context.Context
)
type RecvPro struct {
}
type Rabitmq struct {
Dsn string //rabitmq 配置1
}
func (t *RecvPro) FailAction([]byte) error {
fmt.Print(1)
panic("implement me")
......@@ -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() {
//获取config
logic.GetConfig()
flag.StringVar(&runtype, "runtype", "one", "default config path")
GetConfig()
svclient = service.New()
conclient = context.Background()
if runtype == "one" {
if os.Args[2] == "one" {
//设置协程数量
wg.Add(1)
c := context.Background()
go InsertRecord(c)
go InsertRecord()
//调用服务获取公司信息,然后进行全局赋值
svc := service.New()
companyData,_ = svc.GetCompanyCresitsList(c)
companyData,_ = svclient.GetCompanyCresitsList(conclient)
for _,v :=range companyData{
insertScoreMsg.ComCreditsId = StringTurnInt64(v["id"])
GetCompanyRunInfo(c)
SetSumScore(c)
GetCompanyRunInfo()
basicInfo,_ = svclient.GetBasicInfoByCid(conclient,v["erp_company_code"])
SetSumScore(conclient)
//break
}
......@@ -88,14 +115,22 @@ func main() {
wg.Wait()
}else{
t := &RecvPro{}
var (
dc struct {
Dsn1 *Rabitmq // rab配置1
}
)
paladin.Get("rabitmq.toml").UnmarshalTOML(&dc) //读取配置
queueExchange := &rabbitmq.QueueExchange{
"fengkong_static_count",
"fengkong_static_count",
"fengkong_exchange",
"direct",
"amqp://guest:guest@192.168.2.232:5672/",
"amqp://"+dc.Dsn1.Dsn+"/",
}
for{
......@@ -127,12 +162,13 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//设置协程数量
wg.Add(1)
c := context.Background()
go InsertRecord(c)
conclient = context.Background()
go InsertRecord()
insertScoreMsg.ComCreditsId = StringTurnInt64(rbm.ComCreditsId)
GetCompanyRunInfo(c)
SetSumScore(c)
GetCompanyRunInfo()
basicInfo,_ = svclient.GetBasicInfoByCid(conclient,rbm.ErpCompanyCode)
SetSumScore(conclient)
//赋值完关闭通道
close(socreRecordChan)
......
......@@ -18,7 +18,7 @@ func (d *dao) GetCompanyAddSoreByCid(c context.Context, companyId int64) (res []
return
}
defer d.db.Close()
defer rows.Close()
if err != nil{
fmt.Println("select fail,err:",err)
......
......@@ -8,17 +8,17 @@ import (
)
//通过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 (
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)
return
}
defer d.db.Close()
defer rows.Close()
if err != nil{
fmt.Println("select fail,err:",err)
......
......@@ -50,12 +50,13 @@ func (d *dao)UpdateCompanyBaseInfoForTyc(c context.Context,updateInfo map[string
var(
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 = ? "
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"])
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_address"],updateInfo["legal_representative"],updateInfo["com_credits_id"])
if err != nil {
log.Error("updateScoresdb.DemoExec.Exec(%s) error(%v)", execSql, err)
}
affectNum,err := row.RowsAffected()
return affectNum
......
......@@ -20,7 +20,7 @@ func (d *dao) GetCompanyCresitsList(ctx context.Context) (res []map[string]strin
return
}
defer d.db.Close()
defer rows.Close()
if err != nil{
fmt.Println("select fail,err:",err)
......@@ -47,8 +47,6 @@ func (d *dao) UpdateStaticSumScores(ctx context.Context,com_credits model.ComCre
row.RowsAffected()
defer d.db.Close()
return
}
......@@ -83,6 +81,8 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)(
err = errors.WithStack(err)
return
}
defer rows.Close()
if err != nil{
......@@ -90,6 +90,7 @@ func (d *dao)UpdateComCredits(ctx context.Context,com_credits model.ComCredits)(
return
}
twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{
......@@ -130,6 +131,7 @@ func (d *dao)GetGrade(ctx context.Context,sumScore float64)(res map[string]strin
return
}
twoMap,err := GetAllParam(rows)
for _,v:=range twoMap{
......
......@@ -34,7 +34,6 @@ func (d *dao) GetCompanyScoreFieldsByCid(c context.Context, companyId int64) (re
res = v
break
}
defer d.db.Close()
return
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ type (
InsertScores(ctx context.Context, score model.Scores) (insertId int64, 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)
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)
GetCompanyModelByProjectid(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
res = v
break
}
defer d.db.Close()
fmt.Print(res)
return
}
......
......@@ -32,7 +32,6 @@ func (d *dao) GetModelTopsetByProjectId(c context.Context, projectId int64) (res
res = v
break
}
defer d.db.Close()
return
}
......@@ -6,6 +6,7 @@ import (
"github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/model"
"time"
"github.com/bilibili/kratos/pkg/database/sql"
)
//增加或者修改记录
......@@ -15,13 +16,25 @@ func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int
exitId int
execSql string
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)
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")
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)
defer rows.Close()
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 {
......
......@@ -10,10 +10,7 @@ import (
"encoding/csv"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
"hash/crc32"
"html"
"io"
......@@ -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) {
intval,_ := strconv.ParseInt(val, 10, 64)
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 {
CompanyOrgType string `json:"companyOrgType"`
SocialStaffNum float64 `json:"socialStaffNum"`
RegCapital string `json:"regCapital"`
LegalPersonName string `json:"legalPersonName"`
RegLocation string `json:"regLocation"`
}
type ResultStruct struct {
......@@ -46,6 +48,8 @@ func HttpGet(companyName string)(returnDatas map[string]string) {
returnData := make(map[string]string)
//成立时间
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)
//公司性质
var companyOrgType string
......
......@@ -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方法,获取会员数据
res, err = s.dao.GetBasicInfoByCid(c,companyId)
res, err = s.dao.GetBasicInfoByCid(c,erpCompanyCode)
fmt.Print(err)
return
}
......@@ -130,8 +130,15 @@ func (s *Service) InsertScores(c context.Context,score model.Scores) (res int64,
//调用DB方法,获取会员数据
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
}
......
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