use adapter.go
This commit is contained in:
parent
e5ad3525df
commit
f3022cf5aa
|
@ -1,14 +1,13 @@
|
|||
appname = openscore
|
||||
httpport = 8080
|
||||
runmode = dev
|
||||
autorender = false
|
||||
SessionOn = true
|
||||
copyrequestbody = true
|
||||
sessionon = true
|
||||
dataSourceName = root:123@tcp(localhost:3306)/
|
||||
dbName = openscore
|
||||
redisEndpoint =
|
||||
casdoorEndpoint = http://localhost:8000
|
||||
|
||||
clientId = 9162cb3914b3f1559e9e
|
||||
clientSecret =470d86682d57a75486ed9ae74e748cfbfa6c8774
|
||||
|
||||
jwtSecret = CasdoorSecret
|
||||
casdoorOrganization = "openct"
|
||||
include "mysql.conf"
|
||||
casdoorApplication = "app-openscore"
|
|
@ -1,6 +0,0 @@
|
|||
[mysql]
|
||||
MYSQL_HOST=localhost
|
||||
MYSQL_PORT=3306
|
||||
MYSQL_USER=root
|
||||
MYSQL_PASSWORD=123
|
||||
MYSQL_DATABASE=openscore
|
|
@ -993,4 +993,4 @@ func (c *ApiController) SelfScoreList() {
|
|||
// //----------------------------------------
|
||||
// resp = Response{"10000", "OK", nil}
|
||||
// c.Data["json"] = resp
|
||||
//}
|
||||
//}
|
||||
|
|
1
go.sum
1
go.sum
|
@ -179,6 +179,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
|
|||
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
|
|
3
main.go
3
main.go
|
@ -18,11 +18,12 @@ import (
|
|||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/plugins/cors"
|
||||
_ "github.com/astaxie/beego/session/redis"
|
||||
"github.com/open-ct/openscore/models"
|
||||
routers "github.com/open-ct/openscore/routers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//object.InitAdapter()
|
||||
models.InitAdapter()
|
||||
|
||||
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
|
||||
AllowOrigins: []string{"*"},
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
// Copyright 2022 The OpenCT Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
var adapter *Adapter
|
||||
|
||||
func InitConfig() {
|
||||
err := beego.LoadAppConfig("ini", "../conf/app.conf")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
InitAdapter()
|
||||
}
|
||||
|
||||
func InitAdapter() {
|
||||
adapter = NewAdapter("mysql", beego.AppConfig.String("dataSourceName"))
|
||||
}
|
||||
|
||||
// Adapter represents the MySQL x for policy storage.
|
||||
type Adapter struct {
|
||||
driverName string
|
||||
dataSourceName string
|
||||
engine *xorm.Engine
|
||||
}
|
||||
|
||||
// finalizer is the destructor for Adapter.
|
||||
func finalizer(a *Adapter) {
|
||||
err := a.engine.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// NewAdapter is the constructor for Adapter.
|
||||
func NewAdapter(driverName string, dataSourceName string) *Adapter {
|
||||
a := &Adapter{}
|
||||
a.driverName = driverName
|
||||
a.dataSourceName = dataSourceName
|
||||
|
||||
// Open the DB, create it if not existed.
|
||||
a.open()
|
||||
|
||||
// Call the destructor when the object is released.
|
||||
runtime.SetFinalizer(a, finalizer)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Adapter) createDatabase() error {
|
||||
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer engine.Close()
|
||||
|
||||
_, err = engine.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci", beego.AppConfig.String("dbName")))
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Adapter) open() {
|
||||
if err := a.createDatabase(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName+beego.AppConfig.String("dbName"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
a.engine = engine
|
||||
a.createTable()
|
||||
}
|
||||
|
||||
func (a *Adapter) close() {
|
||||
a.engine.Close()
|
||||
a.engine = nil
|
||||
}
|
||||
|
||||
func (a *Adapter) createTable() {
|
||||
err := a.engine.Sync2(new(Topic))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(SubTopic))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(TestPaper))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(TestPaperInfo))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(ScoreRecord))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(UnderCorrectedPaper))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(PaperDistribution))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(Subject))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.engine.Sync2(new(User))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
var x *xorm.Engine
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
user := beego.AppConfig.String("mysql::MYSQL_USER")
|
||||
password := beego.AppConfig.String("mysql::MYSQL_PASSWORD")
|
||||
host := beego.AppConfig.String("mysql::MYSQL_HOST")
|
||||
port := beego.AppConfig.String("mysql::MYSQL_PORT")
|
||||
database := beego.AppConfig.String("mysql::MYSQL_DATABASE")
|
||||
mysqlDSN := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", user, password, host, port, database)
|
||||
fmt.Println(mysqlDSN)
|
||||
x, err = xorm.NewEngine("mysql", mysqlDSN)
|
||||
if err != nil {
|
||||
fmt.Println("Fail to create xorm engine")
|
||||
panic(err)
|
||||
}
|
||||
x.ShowSQL(true)
|
||||
initMarkingModels()
|
||||
initUserModels()
|
||||
|
||||
}
|
||||
|
||||
func initMarkingModels() {
|
||||
err := x.Sync2(new(Topic), new(SubTopic), new(TestPaper), new(TestPaperInfo), new(ScoreRecord), new(UnderCorrectedPaper), new(PaperDistribution), new(Subject))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initUserModels() {
|
||||
err := x.Sync2(new(User))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
|
@ -15,33 +15,33 @@ type PaperDistribution struct {
|
|||
}
|
||||
|
||||
func (u *PaperDistribution) GetPaperDistribution(id string) error {
|
||||
has, err := x.Where(builder.Eq{"user_id": id}).Get(u)
|
||||
has, err := adapter.engine.Where(builder.Eq{"user_id": id}).Get(u)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find paper distribution")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func FindPaperDistributionByQuestionId(paperDistributions *[]PaperDistribution,questionId int64) error{
|
||||
err:= x.Where("question_id = ?", questionId).Find(paperDistributions)
|
||||
if err!=nil {
|
||||
func FindPaperDistributionByQuestionId(paperDistributions *[]PaperDistribution, questionId int64) error {
|
||||
err := adapter.engine.Where("question_id = ?", questionId).Find(paperDistributions)
|
||||
if err != nil {
|
||||
log.Println("FindPaperDistributionByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
|
||||
func (u *PaperDistribution) Save() error {
|
||||
code, err := x.Insert(u)
|
||||
code, err := adapter.engine.Insert(u)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("insert PaperDistribution fail")
|
||||
log.Println(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func CountUserDistributionNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
paperDistribution :=new (PaperDistribution)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Count(paperDistribution)
|
||||
if err!=nil {
|
||||
func CountUserDistributionNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
paperDistribution := new(PaperDistribution)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Count(paperDistribution)
|
||||
if err != nil {
|
||||
log.Println("countUserDistributionNumberByQuestionId err ")
|
||||
}
|
||||
return count ,err1
|
||||
}
|
||||
return count, err1
|
||||
}
|
||||
|
|
|
@ -16,26 +16,25 @@ type ScoreRecord struct {
|
|||
Score int64 `json:"score"`
|
||||
Test_record_type int64 `json:"test_record_type"`
|
||||
Problem_type int64 `json:"problem_type" xorm:"default(-1)"`
|
||||
Test_finish int64 `json:"testFinish"`
|
||||
|
||||
Test_finish int64 `json:"testFinish"`
|
||||
}
|
||||
|
||||
func (s *ScoreRecord) GetTopic(id int64) error {
|
||||
has, err := x.Where(builder.Eq{"Question_id": id}).Get(s)
|
||||
has, err := adapter.engine.Where(builder.Eq{"Question_id": id}).Get(s)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find user")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (s *ScoreRecord) GetRecordByTestId(testId int64,userId string) error {
|
||||
has, err := x.Where(builder.Eq{"test_id": testId}).Where("user_id=?",userId).Where("test_record_type !=0").Get(s)
|
||||
func (s *ScoreRecord) GetRecordByTestId(testId int64, userId string) error {
|
||||
has, err := adapter.engine.Where(builder.Eq{"test_id": testId}).Where("user_id=?", userId).Where("test_record_type !=0").Get(s)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find user")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (r *ScoreRecord) Save() error {
|
||||
code, err := x.Insert(r)
|
||||
code, err := adapter.engine.Insert(r)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("insert record fail")
|
||||
}
|
||||
|
@ -43,7 +42,7 @@ func (r *ScoreRecord) Save() error {
|
|||
}
|
||||
|
||||
func GetLatestRecords(userId string, records *[]ScoreRecord) error {
|
||||
err := x.Limit(10).Table("score_record").Select("test_id, score, score_time").Where(builder.Eq{"user_id": userId}).Where("test_record_type=1 or test_record_type=2 or test_record_type=3").Desc("record_id").Find(records)
|
||||
err := adapter.engine.Limit(10).Table("score_record").Select("test_id, score, score_time").Where(builder.Eq{"user_id": userId}).Where("test_record_type=1 or test_record_type=2 or test_record_type=3").Desc("record_id").Find(records)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
log.Println("could not find any paper")
|
||||
|
@ -51,160 +50,160 @@ func GetLatestRecords(userId string, records *[]ScoreRecord) error {
|
|||
|
||||
return err
|
||||
}
|
||||
func CountProblemFinishNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=?",6).Count(record)
|
||||
if err!=nil {
|
||||
func CountProblemFinishNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=?", 6).Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountProblemFinishNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountSelfScore(userId string,questionId int64)(count int64,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=0").Where("user_id=?", userId).Count(record)
|
||||
if err!=nil {
|
||||
func CountSelfScore(userId string, questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=0").Where("user_id=?", userId).Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountFailTestNumberByUserId err ")
|
||||
}
|
||||
return count ,err1
|
||||
return count, err1
|
||||
}
|
||||
|
||||
//func CountFailTestNumberByUserId(userId string,questionId int64)(count int64,err error) {
|
||||
// record :=new (ScoreRecord)
|
||||
// count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=5").Where("user_id=?", userId).Count(record)
|
||||
// count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=5").Where("user_id=?", userId).Count(record)
|
||||
// if err!=nil {
|
||||
// log.Println("CountFailTestNumberByUserId err ")
|
||||
// }
|
||||
// return count,err1
|
||||
//}
|
||||
func CountProblemNumberByQuestionId(questionId int64)(count int64) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err := x.Where("question_id = ?", questionId).Where("test_record_type=?",5).Count(record)
|
||||
if err!=nil {
|
||||
func CountProblemNumberByQuestionId(questionId int64) (count int64) {
|
||||
record := new(ScoreRecord)
|
||||
count, err := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=?", 5).Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountProblemNumberByQuestionId err ")
|
||||
}
|
||||
return count
|
||||
}
|
||||
func CountArbitramentFinishNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=?",4).Count(record)
|
||||
if err!=nil {
|
||||
func CountArbitramentFinishNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=?", 4).Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountArbitramentFinishNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
|
||||
//func CountFinishScoreNumberByUserId(userId string,questionId int64)(count int64 ,err error) {
|
||||
// record :=new (ScoreRecord)
|
||||
// count, err1 := x.Where("question_id = ?", questionId).Where("user_id =?",userId).Where("test_finish=1").Count(record)
|
||||
// count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("user_id =?",userId).Where("test_finish=1").Count(record)
|
||||
// if err1!=nil {
|
||||
// log.Println("CountFinishScoreNumberByUserId err ")
|
||||
// }
|
||||
// return count,err1
|
||||
//}
|
||||
|
||||
|
||||
func CountFinishScoreNumberByQuestionId(questionId int64)(count int64 ,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where(" test_record_type!=7 ").Where(" test_record_type!=0 ").Where("test_finish=1").Count(record)
|
||||
if err!=nil {
|
||||
func CountFinishScoreNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where(" test_record_type!=7 ").Where(" test_record_type!=0 ").Where("test_finish=1").Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountFinishScoreNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func FindFinishScoreByQuestionId(finishScores *[]ScoreRecord ,questionId int64)(error) {
|
||||
err := x.Where("question_id = ?", questionId).Where("test_finish=1").Find(*finishScores)
|
||||
if err!=nil {
|
||||
func FindFinishScoreByQuestionId(finishScores *[]ScoreRecord, questionId int64) error {
|
||||
err := adapter.engine.Where("question_id = ?", questionId).Where("test_finish=1").Find(*finishScores)
|
||||
if err != nil {
|
||||
log.Println("CountFinishScoreNumberByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func FindFinishTestByUserId(scoreRecord *[]ScoreRecord,userId string,questionId int64)( err error) {
|
||||
err1 := x.Where("question_id = ?", questionId).Where("user_id=?",userId).Where("test_record_type =1 or test_record_type =2 ").Where("test_finish=1").Find(scoreRecord)
|
||||
if err!=nil {
|
||||
func FindFinishTestByUserId(scoreRecord *[]ScoreRecord, userId string, questionId int64) (err error) {
|
||||
err1 := adapter.engine.Where("question_id = ?", questionId).Where("user_id=?", userId).Where("test_record_type =1 or test_record_type =2 ").Where("test_finish=1").Find(scoreRecord)
|
||||
if err != nil {
|
||||
log.Println("FindFinishTestNumberByUserId err ")
|
||||
}
|
||||
return err1
|
||||
}
|
||||
|
||||
func CountFirstScoreNumberByQuestionId(questionId int64)(count int64 ,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1:= x.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err!=nil {
|
||||
func CountFirstScoreNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountFirstScoreNumberByQuestionId err ")
|
||||
}
|
||||
return count ,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountSecondScoreNumberByQuestionId(questionId int64)(count int64 ,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err!=nil {
|
||||
func CountSecondScoreNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountSecondScoreNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountThirdScoreNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err!=nil {
|
||||
func CountThirdScoreNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("test_finish=1").Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountThirdScoreNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
|
||||
func CountTestScoreNumberByUserId(userId string,questionId int64)(count int64,err1 error) {
|
||||
record :=new (ScoreRecord)
|
||||
count, err := x.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("user_id=?", userId).Count(record)
|
||||
if err!=nil {
|
||||
func CountTestScoreNumberByUserId(userId string, questionId int64) (count int64, err1 error) {
|
||||
record := new(ScoreRecord)
|
||||
count, err := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("user_id=?", userId).Count(record)
|
||||
if err != nil {
|
||||
log.Println("CountFinishTestNumberByUserId err ")
|
||||
}
|
||||
return count,err
|
||||
return count, err
|
||||
}
|
||||
func SumFinishScore(userId string,questionId int64)(sum float64,err1 error) {
|
||||
record :=new (ScoreRecord)
|
||||
sum, err := x.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("user_id=?", userId).Sum(record,"score")
|
||||
if err!=nil {
|
||||
func SumFinishScore(userId string, questionId int64) (sum float64, err1 error) {
|
||||
record := new(ScoreRecord)
|
||||
sum, err := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Where("user_id=?", userId).Sum(record, "score")
|
||||
if err != nil {
|
||||
log.Println("SumFinishScore err ")
|
||||
}
|
||||
return sum,err
|
||||
return sum, err
|
||||
}
|
||||
func FindFinishScoreRecordListByQuestionId (scoreRecordList *[]ScoreRecord , questionId int64) error{
|
||||
err := x.Where("question_id = ?",questionId).Where("test_record_type=1 or test_record_type=2 ").Find(scoreRecordList)
|
||||
if err!=nil {
|
||||
func FindFinishScoreRecordListByQuestionId(scoreRecordList *[]ScoreRecord, questionId int64) error {
|
||||
err := adapter.engine.Where("question_id = ?", questionId).Where("test_record_type=1 or test_record_type=2 ").Find(scoreRecordList)
|
||||
if err != nil {
|
||||
log.Println("FindFinishScoreRecordListByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
|
||||
func FindSelfScoreRecordByUserId(selfScoreRecord *[] ScoreRecord,examinerId string)error {
|
||||
func FindSelfScoreRecordByUserId(selfScoreRecord *[]ScoreRecord, examinerId string) error {
|
||||
|
||||
err := x.Where("user_id=?", examinerId).Where("test_record_type =?",0).Find(selfScoreRecord)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where("user_id=?", examinerId).Where("test_record_type =?", 0).Find(selfScoreRecord)
|
||||
if err != nil {
|
||||
log.Println("FindSelfScoreRecordByUserId err ")
|
||||
}
|
||||
return err
|
||||
|
||||
}
|
||||
func GetTestScoreRecordByTestIdAndUserId(testScoreRecord *ScoreRecord,testId int64,examinerId string) error {
|
||||
func GetTestScoreRecordByTestIdAndUserId(testScoreRecord *ScoreRecord, testId int64, examinerId string) error {
|
||||
|
||||
_, err := x.Where("user_id=?", examinerId).Where("test_id =?", testId).Where(" test_score_type !=?", 0).Get(testScoreRecord)
|
||||
if err!=nil {
|
||||
_, err := adapter.engine.Where("user_id=?", examinerId).Where("test_id =?", testId).Where(" test_score_type !=?", 0).Get(testScoreRecord)
|
||||
if err != nil {
|
||||
log.Println("FindSelfScoreRecordByUserId err ")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func CountTestByScore(question int64, score int64) (count int64,err1 error){
|
||||
func CountTestByScore(question int64, score int64) (count int64, err1 error) {
|
||||
scoreRecord := new(ScoreRecord)
|
||||
count, err := x.Where("score = ?", score).Where("test_record_type=1 or test_record_type=2 ").Where("question_id=?",question).Count(scoreRecord)
|
||||
if err!=nil {
|
||||
count, err := adapter.engine.Where("score = ?", score).Where("test_record_type=1 or test_record_type=2 ").Where("question_id=?", question).Count(scoreRecord)
|
||||
if err != nil {
|
||||
log.Println("CountTestByScored err ")
|
||||
}
|
||||
return count,err
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (s *ScoreRecord) Update() error {
|
||||
code, err := x.Where(builder.Eq{"test_id": s.Test_id}).Update(s)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_id": s.Test_id}).Update(s)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("update ScoreRecord fail")
|
||||
log.Printf("%+v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ type SubTopic struct {
|
|||
}
|
||||
|
||||
func FindSubTopicsByQuestionId(id int64, st *[]SubTopic) error {
|
||||
err := x.Where("question_id = ?", id).Find(st)
|
||||
err := adapter.engine.Where("question_id = ?", id).Find(st)
|
||||
if err != nil {
|
||||
log.Println("could not find any SubTopic")
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func FindSubTopicsByQuestionId(id int64, st *[]SubTopic) error {
|
|||
}
|
||||
|
||||
func GetSubTopicsByTestId(id int64, st *[]SubTopic) error {
|
||||
err := x.Where(builder.Eq{"question_id": id}).Find(st)
|
||||
err := adapter.engine.Where(builder.Eq{"question_id": id}).Find(st)
|
||||
if err != nil {
|
||||
log.Println("could not find any SubTopic")
|
||||
log.Println(err)
|
||||
|
@ -32,15 +32,15 @@ func GetSubTopicsByTestId(id int64, st *[]SubTopic) error {
|
|||
}
|
||||
|
||||
func (st *SubTopic) GetSubTopic(id int64) error {
|
||||
has, err := x.Where(builder.Eq{"question_detail_id": id}).Get(st)
|
||||
has, err := adapter.engine.Where(builder.Eq{"question_detail_id": id}).Get(st)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find SubTopic")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func InsertSubTopic ( subTopic *SubTopic)(err1 error,questionDetailId int64) {
|
||||
_,err := x.Insert(subTopic)
|
||||
if err!=nil {
|
||||
func InsertSubTopic(subTopic *SubTopic) (err1 error, questionDetailId int64) {
|
||||
_, err := adapter.engine.Insert(subTopic)
|
||||
if err != nil {
|
||||
log.Println("GetTopicList err ")
|
||||
}
|
||||
|
||||
|
|
|
@ -4,31 +4,30 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
|
||||
type Subject struct {
|
||||
SubjectId int64 `json:"subjectId" xorm:"pk autoincr"`
|
||||
SubjectName string `json:"subject_name"`
|
||||
SubjectId int64 `json:"subjectId" xorm:"pk autoincr"`
|
||||
SubjectName string `json:"subject_name"`
|
||||
}
|
||||
|
||||
func FindSubjectList ( subjects *[]Subject) error{
|
||||
err := x.Find(subjects)
|
||||
if err!=nil {
|
||||
func FindSubjectList(subjects *[]Subject) error {
|
||||
err := adapter.engine.Find(subjects)
|
||||
if err != nil {
|
||||
log.Println("FindSubjectList err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
|
||||
func InsertSubject ( subject *Subject)(err1 error,questionId int64) {
|
||||
_,err:= x.Insert(subject)
|
||||
if err!=nil {
|
||||
func InsertSubject(subject *Subject) (err1 error, questionId int64) {
|
||||
_, err := adapter.engine.Insert(subject)
|
||||
if err != nil {
|
||||
log.Println("GetTopicList err ")
|
||||
}
|
||||
|
||||
return err,subject.SubjectId
|
||||
return err, subject.SubjectId
|
||||
}
|
||||
func GetSubjectBySubjectName ( subject *Subject,subjectName string) (bool, error){
|
||||
get, err := x.Where("subject_name=?", subjectName).Get(subject)
|
||||
if err!=nil {
|
||||
func GetSubjectBySubjectName(subject *Subject, subjectName string) (bool, error) {
|
||||
get, err := adapter.engine.Where("subject_name=?", subjectName).Get(subject)
|
||||
if err != nil {
|
||||
log.Println("FindSubjectList err ")
|
||||
}
|
||||
return get, err
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
type TestPaper struct {
|
||||
Test_id int64 `json:"test_id" xorm:"pk autoincr"`
|
||||
Question_id int64 `json:"question_id"`
|
||||
Candidate string `json:"candidate"`
|
||||
Candidate string `json:"candidate"`
|
||||
Question_status int64 `json:"question_status"`
|
||||
Examiner_first_id string `json:"examiner_first_id" xorm:"default('-1')"`
|
||||
Examiner_first_score int64 `json:"examiner_first_score" xorm:"default(-1)"`
|
||||
|
@ -26,18 +26,17 @@ type TestPaper struct {
|
|||
Final_score_id string `json:"finale_score_id"`
|
||||
Pratice_error int64 `json:"pratice_error"`
|
||||
Correcting_status int64 `json:"correcting_status"`
|
||||
|
||||
}
|
||||
|
||||
func (t *TestPaper) GetTestPaperByQuestionIdAndQuestionStatus(question_id int64, question_statue int64) error {
|
||||
has, err := x.Where("question_id = ? and question_status = ?", question_id, question_statue).Get(t)
|
||||
has, err := adapter.engine.Where("question_id = ? and question_status = ?", question_id, question_statue).Get(t)
|
||||
if !has || err != nil {
|
||||
log.Println("could not specific test")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (t *TestPaper) GetTestPaperByTestId(testId int64) error {
|
||||
has, err := x.Where("test_id = ?", testId).Get(t)
|
||||
has, err := adapter.engine.Where("test_id = ?", testId).Get(t)
|
||||
if !has || err != nil {
|
||||
log.Println("could not GetTestPaperByTestId")
|
||||
}
|
||||
|
@ -45,7 +44,7 @@ func (t *TestPaper) GetTestPaperByTestId(testId int64) error {
|
|||
}
|
||||
|
||||
func GetTestPaperListByQuestionIdAndQuestionStatus(question_id int64, question_statue int64, tl *[]TestPaper) error {
|
||||
err := x.Where("question_id = ? and question_status = ?", question_id, question_statue).Find(tl)
|
||||
err := adapter.engine.Where("question_id = ? and question_status = ?", question_id, question_statue).Find(tl)
|
||||
if err != nil {
|
||||
log.Println("could not specific test")
|
||||
log.Println(err)
|
||||
|
@ -53,16 +52,16 @@ func GetTestPaperListByQuestionIdAndQuestionStatus(question_id int64, question_s
|
|||
return err
|
||||
}
|
||||
|
||||
func (t *TestPaper) GetTestPaper(id int64) (bool,error) {
|
||||
has, err := x.Where(builder.Eq{"test_id": id}).Get(t)
|
||||
func (t *TestPaper) GetTestPaper(id int64) (bool, error) {
|
||||
has, err := adapter.engine.Where(builder.Eq{"test_id": id}).Get(t)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find test paper")
|
||||
}
|
||||
return has,err
|
||||
return has, err
|
||||
}
|
||||
|
||||
func (t *TestPaper) Update() error {
|
||||
code, err := x.Where(builder.Eq{"test_id": t.Test_id}).Update(t)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_id": t.Test_id}).Update(t)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("update test paper fail")
|
||||
log.Printf("%+v", err)
|
||||
|
@ -70,7 +69,7 @@ func (t *TestPaper) Update() error {
|
|||
return err
|
||||
}
|
||||
func (t *TestPaper) Insert() error {
|
||||
code, err := x.Insert(t)
|
||||
code, err := adapter.engine.Insert(t)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("insert test paper fail")
|
||||
log.Printf("%+v", err)
|
||||
|
@ -78,50 +77,49 @@ func (t *TestPaper) Insert() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func FindTestPaperByQuestionId(question_id int64, t *[]TestPaper) error {
|
||||
err := x.Where("question_id = ?", question_id).Find(t)
|
||||
func FindTestPaperByQuestionId(question_id int64, t *[]TestPaper) error {
|
||||
err := adapter.engine.Where("question_id = ?", question_id).Find(t)
|
||||
if err != nil {
|
||||
log.Println("could not FindTestPaperByQuestionId ")
|
||||
log.Println(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func FindTestPapersByTestId(testId, t *[]TestPaper) error {
|
||||
err := x.Where("question_id = ?", testId).Find(t)
|
||||
func FindTestPapersByTestId(testId, t *[]TestPaper) error {
|
||||
err := adapter.engine.Where("question_id = ?", testId).Find(t)
|
||||
if err != nil {
|
||||
log.Println("could not FindTestPaperByQuestionId ")
|
||||
log.Println(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func FindUnDistributeTest(id int64 , t*[]TestPaper) error {
|
||||
err := x.Where("question_id=?",id).Where("correcting_status=?",0).Find(t)
|
||||
func FindUnDistributeTest(id int64, t *[]TestPaper) error {
|
||||
err := adapter.engine.Where("question_id=?", id).Where("correcting_status=?", 0).Find(t)
|
||||
if err != nil {
|
||||
log.Println("could not GetUnDistributeTest")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
func CountTestDistributionNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
testPaper :=new (TestPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("correcting_status=?",1).Count(testPaper)
|
||||
if err!=nil {
|
||||
func CountTestDistributionNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
testPaper := new(TestPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("correcting_status=?", 1).Count(testPaper)
|
||||
if err != nil {
|
||||
log.Println("CountTestDistributionNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountFailTestNumberByUserId(userId string,questionId int64)(count int64,err error) {
|
||||
testPaper :=new (TestPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("examiner_first_id=? or examiner_second_id=?",userId,userId).Where("question_status=2 or question_status=3 ").Count(testPaper)
|
||||
if err!=nil {
|
||||
func CountFailTestNumberByUserId(userId string, questionId int64) (count int64, err error) {
|
||||
testPaper := new(TestPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("examiner_first_id=? or examiner_second_id=?", userId, userId).Where("question_status=2 or question_status=3 ").Count(testPaper)
|
||||
if err != nil {
|
||||
log.Println("CountFailTestNumberByUserId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
|
||||
func DeleteAllTest(questionId int64) error {
|
||||
_, err := x.Delete(&TestPaper{Question_id:questionId})
|
||||
func DeleteAllTest(questionId int64) error {
|
||||
_, err := adapter.engine.Delete(&TestPaper{Question_id:questionId})
|
||||
if err != nil {
|
||||
log.Println("delete fail")
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ type TestPaperInfo struct {
|
|||
}
|
||||
|
||||
func (t *TestPaperInfo) GetTestPaperInfoByTestIdAndQuestionDetailId(testId int64, questionDetailId int64) error {
|
||||
has, err := x.Where("question_detail_id = ? and test_id = ?", questionDetailId, testId).Get(t)
|
||||
has, err := adapter.engine.Where("question_detail_id = ? and test_id = ?", questionDetailId, testId).Get(t)
|
||||
if !has || err != nil {
|
||||
log.Println("could not specific info")
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func (t *TestPaperInfo) GetTestPaperInfoByTestIdAndQuestionDetailId(testId int64
|
|||
}
|
||||
|
||||
func (t *TestPaperInfo) GetTestPaperInfo(id int64) error {
|
||||
has, err := x.Where(builder.Eq{"test_detail_id": id}).Get(t)
|
||||
has, err := adapter.engine.Where(builder.Eq{"test_detail_id": id}).Get(t)
|
||||
if !has && err != nil {
|
||||
log.Println("could not find test paper info")
|
||||
log.Println(err)
|
||||
|
@ -44,7 +44,7 @@ func (t *TestPaperInfo) GetTestPaperInfo(id int64) error {
|
|||
}
|
||||
|
||||
func (t *TestPaperInfo) Update() error {
|
||||
code, err := x.Where(builder.Eq{"test_detail_id": t.Test_detail_id}).AllCols().Update(t)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_detail_id": t.Test_detail_id}).AllCols().Update(t)
|
||||
if code == 0 && err != nil {
|
||||
log.Println("update test paper info fail")
|
||||
log.Println(err)
|
||||
|
@ -52,7 +52,7 @@ func (t *TestPaperInfo) Update() error {
|
|||
return err
|
||||
}
|
||||
func (t *TestPaperInfo) Insert() error {
|
||||
code, err := x.Insert(t)
|
||||
code, err := adapter.engine.Insert(t)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("Insert test paper info fail")
|
||||
log.Println(err)
|
||||
|
@ -61,7 +61,7 @@ func (t *TestPaperInfo) Insert() error {
|
|||
}
|
||||
|
||||
func GetTestInfoListByTestId(id int64, as *[]TestPaperInfo) error {
|
||||
err := x.Where("test_id = ?", id).Find(as)
|
||||
err := adapter.engine.Where("test_id = ?", id).Find(as)
|
||||
if err != nil {
|
||||
log.Println("could not find any paper")
|
||||
}
|
||||
|
@ -69,15 +69,15 @@ func GetTestInfoListByTestId(id int64, as *[]TestPaperInfo) error {
|
|||
}
|
||||
|
||||
func GetTestInfoPicListByTestId(id int64, as *[]string) error {
|
||||
err := x.Table("test_paper_info").Select("pic_src").Where("test_id = ?", id).Find(as)
|
||||
err := adapter.engine.Table("test_paper_info").Select("pic_src").Where("test_id = ?", id).Find(as)
|
||||
if err != nil {
|
||||
log.Println("could not find any paper")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func FindTestPaperInfoByQuestionDetailId(questionDetailId int64, t *[]TestPaperInfo) error {
|
||||
err := x.Where("question_detail_id = ?", questionDetailId).Find(t)
|
||||
func FindTestPaperInfoByQuestionDetailId(questionDetailId int64, t *[]TestPaperInfo) error {
|
||||
err := adapter.engine.Where("question_detail_id = ?", questionDetailId).Find(t)
|
||||
if err != nil {
|
||||
log.Println("could not FindTestPaperInfoByQuestionId ")
|
||||
log.Println(err)
|
||||
|
@ -85,7 +85,7 @@ func FindTestPaperInfoByQuestionDetailId(questionDetailId int64, t *[]TestPaper
|
|||
return err
|
||||
}
|
||||
func (u *TestPaperInfo) Delete() error {
|
||||
_, err := x.Where(builder.Eq{"test_id": u.Test_id}).Delete(u)
|
||||
_, err := adapter.engine.Where(builder.Eq{"test_id": u.Test_id}).Delete(u)
|
||||
if err != nil {
|
||||
log.Println("delete fail")
|
||||
}
|
||||
|
|
|
@ -19,50 +19,50 @@ type Topic struct {
|
|||
Score_type int64 `json:"score_type"`
|
||||
Import_number int64 `json:"import_number"`
|
||||
Import_time time.Time `json:"import_time"`
|
||||
Subject_Id int64 `json:"subject_id"`
|
||||
Subject_Id int64 `json:"subject_id"`
|
||||
SelfScoreRate int64 `json:"self_score_rate"`
|
||||
}
|
||||
|
||||
func (t *Topic) GetTopic(id int64) error {
|
||||
has, err := x.Where(builder.Eq{"question_id": id}).Get(t)
|
||||
has, err := adapter.engine.Where(builder.Eq{"question_id": id}).Get(t)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find topic")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
func GetTopicList ( topics *[]Topic) error{
|
||||
err := x.Find(topics)
|
||||
if err!=nil {
|
||||
func GetTopicList(topics *[]Topic) error {
|
||||
err := adapter.engine.Find(topics)
|
||||
if err != nil {
|
||||
log.Println("GetTopicList err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindTopicBySubNameList ( topics *[]Topic,subjectName string) error{
|
||||
err := x.Where("subject_name=?",subjectName).Find(topics)
|
||||
if err!=nil {
|
||||
func FindTopicBySubNameList(topics *[]Topic, subjectName string) error {
|
||||
err := adapter.engine.Where("subject_name=?", subjectName).Find(topics)
|
||||
if err != nil {
|
||||
log.Println("FindTopicBySubNameList err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindTopicList ( topics *[]Topic) error{
|
||||
err := x.Find(topics)
|
||||
if err!=nil {
|
||||
func FindTopicList(topics *[]Topic) error {
|
||||
err := adapter.engine.Find(topics)
|
||||
if err != nil {
|
||||
log.Println("FindTopicList err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func InsertTopic ( topic *Topic)(err1 error,questionId int64) {
|
||||
_,err:= x.Insert(topic)
|
||||
if err!=nil {
|
||||
func InsertTopic(topic *Topic) (err1 error, questionId int64) {
|
||||
_, err := adapter.engine.Insert(topic)
|
||||
if err != nil {
|
||||
log.Println("GetTopicList err ")
|
||||
}
|
||||
|
||||
return err,topic.Question_id
|
||||
return err, topic.Question_id
|
||||
}
|
||||
|
||||
//func Update ( topic *Topic,questionId int64)error {
|
||||
// _,err:= x.Where("question_id=?",questionId).Update(&topic)
|
||||
// _,err:= adapter.engine.Where("question_id=?",questionId).Update(&topic)
|
||||
// if err!=nil {
|
||||
// log.Println("Update topic err ")
|
||||
// }
|
||||
|
@ -70,10 +70,10 @@ func InsertTopic ( topic *Topic)(err1 error,questionId int64) {
|
|||
// return err
|
||||
//}
|
||||
func (t *Topic) Update() error {
|
||||
code, err := x.Where(builder.Eq{"question_id": t.Question_id}).Update(t)
|
||||
code, err := adapter.engine.Where(builder.Eq{"question_id": t.Question_id}).Update(t)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("update Topic paper fail")
|
||||
log.Printf("%+v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ type UnderCorrectedPaper struct {
|
|||
Question_id int64 `json:"question_id"`
|
||||
Test_question_type int64 `json:"test_question_type"`
|
||||
Problem_type int64 `json:"problem_type" xorm:"default(-1)"`
|
||||
Problem_message string `json:"test_message"`
|
||||
Self_score_id string `json:"self_score_id"`
|
||||
Problem_message string `json:"test_message"`
|
||||
Self_score_id string `json:"self_score_id"`
|
||||
}
|
||||
|
||||
func (u *UnderCorrectedPaper) GetUnderCorrectedPaper(userId string, testId int64) error {
|
||||
has, err := x.Where("test_id=?",testId).Where("user_id =?",userId).Get(u)
|
||||
has, err := adapter.engine.Where("test_id=?", testId).Where("user_id =?", userId).Get(u)
|
||||
if !has || err != nil {
|
||||
log.Println("could not find under corrected paper")
|
||||
log.Println(err)
|
||||
|
@ -27,21 +27,21 @@ func (u *UnderCorrectedPaper) GetUnderCorrectedPaper(userId string, testId int64
|
|||
}
|
||||
|
||||
func (u *UnderCorrectedPaper) Delete() error {
|
||||
code, err := x.Where(builder.Eq{"test_id": u.Test_id, "user_id": u.User_id}).Delete(u)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_id": u.Test_id, "user_id": u.User_id}).Delete(u)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("delete fail")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (u *UnderCorrectedPaper) SupervisorDelete() error {
|
||||
code, err := x.Where(builder.Eq{"test_id": u.Test_id}).Where(" test_question_type =4 or test_question_type =6 or test_question_type =7").Delete(u)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_id": u.Test_id}).Where(" test_question_type =4 or test_question_type =6 or test_question_type =7").Delete(u)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("delete fail")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (u *UnderCorrectedPaper) SelfMarkDelete() error {
|
||||
code, err := x.Where(builder.Eq{"test_id": u.Test_id}).Where(" test_question_type =0 ").Delete(u)
|
||||
code, err := adapter.engine.Where(builder.Eq{"test_id": u.Test_id}).Where(" test_question_type =0 ").Delete(u)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("delete fail")
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (u *UnderCorrectedPaper) SelfMarkDelete() error {
|
|||
}
|
||||
|
||||
func (u *UnderCorrectedPaper) Save() error {
|
||||
code, err := x.Insert(u)
|
||||
code, err := adapter.engine.Insert(u)
|
||||
if code == 0 || err != nil {
|
||||
log.Println("insert paper fail")
|
||||
log.Println(err)
|
||||
|
@ -59,7 +59,7 @@ func (u *UnderCorrectedPaper) Save() error {
|
|||
|
||||
func (u *UnderCorrectedPaper) IsDuplicate() (bool, error) {
|
||||
var temp UnderCorrectedPaper
|
||||
has, err := x.Where(builder.Eq{"test_id": u.Test_id, "problem_type": u.Problem_type}).Get(&temp)
|
||||
has, err := adapter.engine.Where(builder.Eq{"test_id": u.Test_id, "problem_type": u.Problem_type}).Get(&temp)
|
||||
if !has || err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
@ -67,122 +67,121 @@ func (u *UnderCorrectedPaper) IsDuplicate() (bool, error) {
|
|||
}
|
||||
|
||||
func GetDistributedPaperByUserId(id string, up *[]UnderCorrectedPaper) error {
|
||||
err := x.Where("user_id = ?", id).Find(up)
|
||||
err := adapter.engine.Where("user_id = ?", id).Find(up)
|
||||
if err != nil {
|
||||
log.Println("could not find any paper")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func CountRemainingTestNumberByUserId(questionId int64 ,userId string)(count int64,err error) {
|
||||
underCorrectedPaper:=new (UnderCorrectedPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("user_id=?",userId).Where("test_question_type=1 or test_question_type=2").Count(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
func CountRemainingTestNumberByUserId(questionId int64, userId string) (count int64, err error) {
|
||||
underCorrectedPaper := new(UnderCorrectedPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("user_id=?", userId).Where("test_question_type=1 or test_question_type=2").Count(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("CountRemainingTestNumberByUserId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountArbitramentUnFinishNumberByQuestionId(questionId int64 )(count int64,err error) {
|
||||
underCorrectedPaper:=new (UnderCorrectedPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_question_type=4").Count(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
func CountArbitramentUnFinishNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
underCorrectedPaper := new(UnderCorrectedPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_question_type=4").Count(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("CountRemainingTestNumberByUserId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountProblemUnFinishNumberByQuestionId(questionId int64 )(count int64,err error) {
|
||||
underCorrectedPaper:=new (UnderCorrectedPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Where("test_question_type=6").Count(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
func CountProblemUnFinishNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
underCorrectedPaper := new(UnderCorrectedPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Where("test_question_type=6").Count(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("CountProblemUnFinishNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountUnScoreTestNumberByQuestionId(questionId int64 )(count int64,err error) {
|
||||
underCorrectedPaper:=new (UnderCorrectedPaper)
|
||||
count, err1 := x.Where("question_id = ?", questionId).Count(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
func CountUnScoreTestNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
underCorrectedPaper := new(UnderCorrectedPaper)
|
||||
count, err1 := adapter.engine.Where("question_id = ?", questionId).Count(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("CountUnScoreTestNumberByQuestionId err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
|
||||
func GetUnderCorrectedPaperByUserIdAndTestId(underCorrectedPaper * UnderCorrectedPaper ,userId string,testId int64) error {
|
||||
func GetUnderCorrectedPaperByUserIdAndTestId(underCorrectedPaper *UnderCorrectedPaper, userId string, testId int64) error {
|
||||
|
||||
_, err := x.Where("user_id=?", userId).Where("test_id =?", testId).Where(" test_question_type !=?", 0).Get(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
_, err := adapter.engine.Where("user_id=?", userId).Where("test_id =?", testId).Where(" test_question_type !=?", 0).Get(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("GetUnderCorrectedPaperByUserIdAndTestId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func GetUnderCorrectedSupervisorPaperByTestQuestionTypeAndTestId(underCorrectedPaper * UnderCorrectedPaper ,testId int64) error {
|
||||
func GetUnderCorrectedSupervisorPaperByTestQuestionTypeAndTestId(underCorrectedPaper *UnderCorrectedPaper, testId int64) error {
|
||||
|
||||
_, err := x.Where("test_id =?", testId).Where(" test_question_type =4 or test_question_type =6 or test_question_type =7").Get(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
_, err := adapter.engine.Where("test_id =?", testId).Where(" test_question_type =4 or test_question_type =6 or test_question_type =7").Get(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("GetUnderCorrectedPaperByUserIdAndTestId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func GetSelfScorePaperByTestQuestionTypeAndTestId(underCorrectedPaper * UnderCorrectedPaper ,testId int64,userId string) error {
|
||||
func GetSelfScorePaperByTestQuestionTypeAndTestId(underCorrectedPaper *UnderCorrectedPaper, testId int64, userId string) error {
|
||||
|
||||
_, err := x.Where("test_id =?", testId).Where(" test_question_type =0").Where("user_Id = ?",userId).Get(underCorrectedPaper)
|
||||
if err!=nil {
|
||||
_, err := adapter.engine.Where("test_id =?", testId).Where(" test_question_type =0").Where("user_Id = ?", userId).Get(underCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("GetSelfScorePaperByTestQuestionTypeAndTestId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
|
||||
func FindArbitramentUnderCorrectedPaperByQuestionId(arbitramentUnderCorrectedPaper *[]UnderCorrectedPaper, questionId int64) error {
|
||||
|
||||
func FindArbitramentUnderCorrectedPaperByQuestionId(arbitramentUnderCorrectedPaper *[] UnderCorrectedPaper,questionId int64)error{
|
||||
|
||||
err := x.Where("question_id=?", questionId).Where(" test_question_type =?", 4).Find(arbitramentUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where("question_id=?", questionId).Where(" test_question_type =?", 4).Find(arbitramentUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindArbitramentUnderCorrectedPaperByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindAllArbitramentUnderCorrectedPaper(arbitramentUnderCorrectedPaper *[] UnderCorrectedPaper,questionId int64)error{
|
||||
func FindAllArbitramentUnderCorrectedPaper(arbitramentUnderCorrectedPaper *[]UnderCorrectedPaper, questionId int64) error {
|
||||
|
||||
err := x.Where(" test_question_type =?", 4).Where("question_id= ?",questionId).Find(arbitramentUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where(" test_question_type =?", 4).Where("question_id= ?", questionId).Find(arbitramentUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindAllArbitramentUnderCorrectedPaper err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
|
||||
func FindProblemUnderCorrectedPaperByQuestionId(problemUnderCorrectedPaper *[] UnderCorrectedPaper,questionId int64) error{
|
||||
func FindProblemUnderCorrectedPaperByQuestionId(problemUnderCorrectedPaper *[]UnderCorrectedPaper, questionId int64) error {
|
||||
|
||||
err := x.Where("question_id=?", questionId).Where(" test_question_type =?", 6).Find(problemUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where("question_id=?", questionId).Where(" test_question_type =?", 6).Find(problemUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindProblemUnderCorrectedPaperByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindSelfUnderCorrectedPaperByQuestionId(selfUnderCorrectedPaper *[] UnderCorrectedPaper,questionId int64) error{
|
||||
func FindSelfUnderCorrectedPaperByQuestionId(selfUnderCorrectedPaper *[]UnderCorrectedPaper, questionId int64) error {
|
||||
|
||||
err := x.Where("question_id=?", questionId).Where(" test_question_type =?", 7).Find(selfUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where("question_id=?", questionId).Where(" test_question_type =?", 7).Find(selfUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindSelfUnderCorrectedPaperByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindSelfMarkPaperByQuestionId(selfMarkUnderCorrectedPaper *[]UnderCorrectedPaper,questionId int64) error{
|
||||
func FindSelfMarkPaperByQuestionId(selfMarkUnderCorrectedPaper *[]UnderCorrectedPaper, questionId int64) error {
|
||||
|
||||
err := x.Where("question_id=?", questionId).Where(" test_question_type =?", 7).Find(selfMarkUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where("question_id=?", questionId).Where(" test_question_type =?", 7).Find(selfMarkUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindSelfMarkPaperByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func FindProblemUnderCorrectedList(problemUnderCorrectedPaper *[] UnderCorrectedPaper) error{
|
||||
func FindProblemUnderCorrectedList(problemUnderCorrectedPaper *[]UnderCorrectedPaper) error {
|
||||
|
||||
err := x.Where(" test_question_type =?", 6).Find(problemUnderCorrectedPaper)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Where(" test_question_type =?", 6).Find(problemUnderCorrectedPaper)
|
||||
if err != nil {
|
||||
log.Println("FindProblemUnderCorrectedList err ")
|
||||
}
|
||||
return err
|
||||
return err
|
||||
}
|
||||
func GetDistributedTestIdPaperByUserId(id string, up *[]int64) error {
|
||||
err := x.Table("under_corrected_paper").Select("test_id").Where("user_id = ?", id).Where(" test_question_type=0 or test_question_type=1 or test_question_type=2 or test_question_type=3").Find(up)
|
||||
err := adapter.engine.Table("under_corrected_paper").Select("test_id").Where("user_id = ?", id).Where(" test_question_type=0 or test_question_type=1 or test_question_type=2 or test_question_type=3").Find(up)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
log.Println("could not find any paper")
|
||||
|
@ -190,10 +189,10 @@ func GetDistributedTestIdPaperByUserId(id string, up *[]int64) error {
|
|||
return err
|
||||
}
|
||||
func GetUnMarkSelfTestIdPaperByUserId(id string, up *[]int64) error {
|
||||
err := x.Table("under_corrected_paper").Select("test_id").Where("user_id = ?", id).Where(" test_question_type=0 ").Find(up)
|
||||
err := adapter.engine.Table("under_corrected_paper").Select("test_id").Where("user_id = ?", id).Where(" test_question_type=0 ").Find(up)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
log.Println("GetUnMarkSelfTestIdPaperByUserId")
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,75 +19,74 @@ type User struct {
|
|||
Email string `json:"email"`
|
||||
Login_time time.Time `json:"login_time"`
|
||||
Exist_time time.Time `json:"exist_time"`
|
||||
Online_time int64 `json:"online_time"`
|
||||
Online_time int64 `json:"online_time"`
|
||||
Subject_name string `json:"subject_name"`
|
||||
Status int64 `json:"status"`
|
||||
UserType int64 `json:"userType"`
|
||||
IsDistribute int64 `json:"isDistribute"`
|
||||
|
||||
QuestionId int64 `json:"question_id"`
|
||||
|
||||
QuestionId int64 `json:"question_id"`
|
||||
}
|
||||
|
||||
func (u *User) GetUser(id string) error {
|
||||
has, err := x.Where(builder.Eq{"user_id": id}).Get(u)
|
||||
has, err := adapter.engine.Where(builder.Eq{"user_id": id}).Get(u)
|
||||
if !has || err != nil {
|
||||
log.Println("could not found user")
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (u *User) Update() error {
|
||||
_,err := x.Update(u)
|
||||
_, err := adapter.engine.Update(u)
|
||||
if err != nil {
|
||||
log.Println("could not Update user")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CountOnlineNumberUnDistribute( )(count int64,err error) {
|
||||
user :=new (User)
|
||||
count, err1 := x.Where("status = ? ", 1).Where(" user_type=?",1).Where("is_distribute = ?",0).Count(user)
|
||||
if err!=nil {
|
||||
func CountOnlineNumberUnDistribute() (count int64, err error) {
|
||||
user := new(User)
|
||||
count, err1 := adapter.engine.Where("status = ? ", 1).Where(" user_type=?", 1).Where("is_distribute = ?", 0).Count(user)
|
||||
if err != nil {
|
||||
log.Println("CountOnlineNumber err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func CountOnlineUserNumberByQuestionId(questionId int64)(count int64,err error) {
|
||||
user :=new (User)
|
||||
count, err1 := x.Where("status = ? ", 1).Where(" user_type=?",1).Where("is_distribute = ?",1).Where("question_id=?",questionId).Count(user)
|
||||
if err!=nil {
|
||||
func CountOnlineUserNumberByQuestionId(questionId int64) (count int64, err error) {
|
||||
user := new(User)
|
||||
count, err1 := adapter.engine.Where("status = ? ", 1).Where(" user_type=?", 1).Where("is_distribute = ?", 1).Where("question_id=?", questionId).Count(user)
|
||||
if err != nil {
|
||||
log.Println("CountOnlineNumber err ")
|
||||
}
|
||||
return count,err1
|
||||
return count, err1
|
||||
}
|
||||
func FindOnlineUserNumberByQuestionId(users *[]User ,questionId int64)( error) {
|
||||
err := x.Where("status = ? ", 1).Where(" user_type=?",1).Where("is_distribute = ?",1).Where("question_id=?",questionId).Find(users)
|
||||
if err!=nil {
|
||||
func FindOnlineUserNumberByQuestionId(users *[]User, questionId int64) error {
|
||||
err := adapter.engine.Where("status = ? ", 1).Where(" user_type=?", 1).Where("is_distribute = ?", 1).Where("question_id=?", questionId).Find(users)
|
||||
if err != nil {
|
||||
log.Println("FindOnlineUserNumberByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func FindUserNumberByQuestionId(users *[]User ,questionId int64)( error) {
|
||||
err := x.Where(" user_type=?",1).Where("is_distribute = ?",1).Where("question_id=?",questionId).Find(users)
|
||||
if err!=nil {
|
||||
func FindUserNumberByQuestionId(users *[]User, questionId int64) error {
|
||||
err := adapter.engine.Where(" user_type=?", 1).Where("is_distribute = ?", 1).Where("question_id=?", questionId).Find(users)
|
||||
if err != nil {
|
||||
log.Println("FindOnlineUserNumberByQuestionId err ")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func FindUsers( u *[]User) error {
|
||||
err := x.Where("status = ? ", 1).Where(" user_type=?",1).Where("is_distribute = ?",0).Find(u)
|
||||
func FindUsers(u *[]User) error {
|
||||
err := adapter.engine.Where("status = ? ", 1).Where(" user_type=?", 1).Where("is_distribute = ?", 0).Find(u)
|
||||
if err != nil {
|
||||
log.Println("could not FindUsers ")
|
||||
log.Println(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func FindNewUserId(id1 string,id2 string,questionId int64) (newId string ){
|
||||
func FindNewUserId(id1 string, id2 string, questionId int64) (newId string) {
|
||||
var Ids []string
|
||||
err := x.Table("user").Where("user_id !=?", id1).Where("user_id !=?", id2).Where("question_id=?",questionId).Where("status=?",1).Select("user_id").Find(&Ids)
|
||||
if err!=nil {
|
||||
err := adapter.engine.Table("user").Where("user_id !=?", id1).Where("user_id !=?", id2).Where("question_id=?", questionId).Where("status=?", 1).Select("user_id").Find(&Ids)
|
||||
if err != nil {
|
||||
log.Println("FindNewUserId err")
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue