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
}
......
......@@ -139,3 +139,91 @@
[2019/11/25 10:10:40.606] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:56] caipu-server start
[2019/11/25 10:17:03.956] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:56] caipu-server start
[2019/11/25 10:17:41.843] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 11:05:31.260] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:05:57.945] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:06:24.565] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:07:09.298] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:07:32.426] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:07:44.144] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:07:58.406] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:08:09.405] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:08:18.052] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:08:35.048] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:15:58.866] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:16:25.611] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:16:33.485] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:16:42.338] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:19:30.689] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:20:04.876] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:20:53.952] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:21:08.519] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:21:38.955] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:24:09.355] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:24:29.032] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:24:36.357] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:25:37.609] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:27:57.132] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:29:16.271] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:31:26.676] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:31:45.648] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:31:54.107] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:08.162] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:22.410] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:33.503] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:40.991] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:51.009] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:32:58.812] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:33:25.639] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:33:33.157] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:35:13.300] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:35:36.926] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:37:00.487] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:38:52.623] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:39:11.305] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:39:29.516] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:41:07.845] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:48:00.471] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:49:07.113] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:50:41.784] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 11:51:11.953] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:37:30.454] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:41:50.379] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:42:14.771] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:42:35.434] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:42:50.451] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:44:10.739] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:44:53.373] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:47:14.713] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:47:31.565] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:48:50.246] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:49:12.904] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:51:48.841] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:51:59.804] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 13:55:03.347] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:03:55.439] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:04:33.969] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:04:41.093] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:05:46.375] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:06:01.927] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:07:29.742] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:08:17.441] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:08:47.229] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:08:59.329] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:11:44.858] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:58] caipu-server start
[2019/11/25 14:15:03.769] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:15:33.797] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:16:38.994] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:16:42.909] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:22:06.918] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:25:54.037] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:26:18.766] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:26:57.074] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:27:05.682] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:59] caipu-server start
[2019/11/25 14:28:35.763] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:29:23.430] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:29:38.412] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:29:48.466] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:30:36.747] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:31:31.937] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:41:01.973] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
[2019/11/25 14:41:52.333] [INFO] [/usr/local/var/www/ichunt/kaopu-server/cmd/static/main.go:62] caipu-server start
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