Commit 90dc6642 by Joneq

增加sql插入

parent c66f1d59
...@@ -16,12 +16,13 @@ func CompanyInfo() { ...@@ -16,12 +16,13 @@ func CompanyInfo() {
//成立时间(1分) //成立时间(1分)
func EstablishmentTime() { func EstablishmentTime() {
setInserScoreHeader(1,1,8) setInserScoreHeader(1,1,8)
inserScoreMsg.TotalScore = 5 insertScoreMsg.TotalScore = 5
inserScoreMsg.FinalScore = 5 insertScoreMsg.FinalScore = 5
inserScoreMsg.CurrentScore = 2 insertScoreMsg.CurrentScore = 2
inserScoreMsg.Weight = 50 insertScoreMsg.Weight = 50
inserScoreMsg.ComCreditsId = 2 insertScoreMsg.ComCreditsId = 2
socreRecordChan <- inserScoreMsg
socreRecordChan <- insertScoreMsg
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/bilibili/kratos/pkg/conf/paladin" "github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log" "github.com/bilibili/kratos/pkg/log"
"kaopu-server/internal/dao"
"kaopu-server/internal/model" "kaopu-server/internal/model"
"kaopu-server/internal/service" "kaopu-server/internal/service"
"time" "time"
...@@ -17,8 +18,8 @@ var ( ...@@ -17,8 +18,8 @@ var (
companyData []map[string]interface{} companyData []map[string]interface{}
//插入分值的通道,限制一千,超过等待 //插入分值的通道,限制一千,超过等待
socreRecordChan = make(chan model.Scores, 1000) socreRecordChan = make(chan model.Scores, 1000)
// //分数的数据
inserScoreMsg model.Scores insertScoreMsg model.Scores
) )
...@@ -29,17 +30,23 @@ func main() { ...@@ -29,17 +30,23 @@ func main() {
getConfig() getConfig()
go insertRecord() go insertRecord()
svc := service.New()
ctx := context.Background()
//调用服务获取公司信息,然后进行全局赋值 //调用服务获取公司信息,然后进行全局赋值
companyData,_ = svc.GetCompanyCresitsList(ctx) companyData,_ = svc.GetCompanyCresitsList(ctx)
CompanyInfo() CompanyInfo()
//insertId,err := svc.InsertScores(ctx,insertScoreMsg)
//fmt.Print(err)
//fmt.Print(insertId)
//fmt.Print(companyData) //fmt.Print(companyData)
//EnterPriseCredit() //EnterPriseCredit()
//HistoryBussiness() //HistoryBussiness()
//PersonalCredit() //PersonalCredit()
//AddScore() //AddScore()
time.Sleep(1 * time.Millisecond)
//延迟100秒用来执行协程的错误返回
time.Sleep(100000 * time.Millisecond)
} }
...@@ -61,22 +68,21 @@ func getConfig() { ...@@ -61,22 +68,21 @@ func getConfig() {
func insertRecord() { func insertRecord() {
//声明service层 //声明service层
svc := service.New() connect := dao.New()
ctx := context.Background() ctx := context.Background()
for { for {
// 从通道中拿出消息 // 从通道中拿出消息
insertRecord := <- socreRecordChan insertScoreMsg := <- socreRecordChan
svc.in insertId,err := connect.InsertScores(ctx,insertScoreMsg)
fmt.Print(insertRecord) fmt.Print(err)
fmt.Print(insertId)
//插入数据 //插入数据
} }
} }
//设置插入的分数头 //设置插入的分数头
func setInserScoreHeader(_typy,project_pid,project_id int8) { func setInserScoreHeader(_typy,project_pid,project_id int8) {
inserScoreMsg.Type = _typy insertScoreMsg.Type = _typy
inserScoreMsg.ProjectPid = project_pid insertScoreMsg.ProjectPid = project_pid
inserScoreMsg.ProjectId = project_id insertScoreMsg.ProjectId = project_id
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ type ( ...@@ -22,7 +22,7 @@ type (
//---静态开始 //---静态开始
GetCompanyCresitsList(ctx context.Context) (r []map[string]interface{}, err error) GetCompanyCresitsList(ctx context.Context) (r []map[string]interface{}, err error)
InsertScores(ctx context.Context, score *model.Scores) (insertId int64, err error) InsertScores(ctx context.Context, score model.Scores) (insertId int64, err error)
//---静态结束 //---静态结束
} }
...@@ -37,6 +37,7 @@ type dao struct { ...@@ -37,6 +37,7 @@ type dao struct {
mcExpire int32 mcExpire int32
} }
func checkErr(err error) { func checkErr(err error) {
if err != nil { if err != nil {
panic(err) panic(err)
......
...@@ -4,19 +4,23 @@ import ( ...@@ -4,19 +4,23 @@ import (
"context" "context"
"fmt" "fmt"
"kaopu-server/internal/model" "kaopu-server/internal/model"
"github.com/bilibili/kratos/pkg/log"
) )
//增加记录 //增加记录
func (d *dao) insertScores(ctx context.Context,score *model.Scores) (res int64,err error) { func (d *dao) InsertScores(ctx context.Context,score model.Scores) (insertId int64,err error) {
stmt,_:= d.db.Prepare("INSERT INTO chat_list (roomstr, urid,srid) VALUES (?,?,?)") insertSql := "INSERT INTO `lie_scores` (`type`)VALUES(?)"
row, err := stmt.Exec(ctx,score.CreateTime,score.CurrentScore) row,err := d.db.Exec(ctx,insertSql,1)
if err != nil{ fmt.Print(11111)
fmt.Println("select fail,err:",err)
if err != nil {
log.Error("db.DemoExec.Exec(%s) error(%v)", insertSql, err)
return
} }
row.LastInsertId()
defer d.db.Close() defer d.db.Close()
res,_ = row.LastInsertId()
return return
} }
\ No newline at end of file
...@@ -71,10 +71,13 @@ func (s *Service) GetCompanyCresitsList(ctx context.Context) (res []map[string]i ...@@ -71,10 +71,13 @@ func (s *Service) GetCompanyCresitsList(ctx context.Context) (res []map[string]i
} }
//插入分数记录 //插入分数记录
func (s *Service) insertScores(ctx context.Context,score *model.Scores) (inserId int64, err error) { func (s *Service) InsertScores(ctx context.Context,score model.Scores) (insertId int64, err error) {
//调用DB方法,获取会员数据 //调用DB方法,获取会员数据
inserId,_ = s.dao.InsertScores(ctx,score) insertId,err = s.dao.InsertScores(ctx,score)
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
}
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