Commit 90dc6642 by Joneq

增加sql插入

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