Browse Source

问卷调查

develop
娄文智 5 months ago
parent
commit
01bf2f0e65
8 changed files with 64 additions and 33 deletions
  1. +2
    -2
      conf/app.go
  2. +5
    -9
      conf/db.go
  3. +7
    -7
      db/db.go
  4. +2
    -2
      main.go
  5. +2
    -2
      web/controllers/c_surveysheet_controller.go
  6. +2
    -9
      web/controllers/user_controller.go
  7. +17
    -2
      web/models/c_surveysheet.go
  8. +27
    -0
      web/models/c_surveysheet_result.go

+ 2
- 2
conf/app.go View File

@ -37,10 +37,10 @@ var AppConfig AppConf = AppConf{
TimeFormat: "Mon, 01 Jan 2006 15:04:05 GMT",
Charset: "UTF-8",
Other: Other{
IgnoreURLs: []string{"/", "/user/login", "/user/courts", "/admin/tabnames/download", "/user/getimg", "/api"}, //免token验证路径
IgnoreURLs: []string{"/", "/user/login", "/user/courts", "/admin/tabnames/download", "/user/getimg", "/api", "/admin/c_surveysheet/selectinfo"}, //免token验证路径addinfo
JWTTimeout: 72000,
LogLevel: "debug",
Secret: "SSW_WebPlatform123456",
},
PublicRute: []string{"/sysMenu", "/user/getuserinfo", "/user/pwd", "/user/avatar", "/user/profile", "/user/getimg", "/admin/tabnames/list", "/admin/stdeftab/selectarr", "/admin/stdeftab/selectall", "/api"}, //免权限检查路径
PublicRute: []string{"/sysMenu", "/user/getuserinfo", "/user/pwd", "/user/avatar", "/user/profile", "/user/getimg", "/admin/tabnames/list", "/admin/stdeftab/selectarr", "/admin/stdeftab/selectall", "/api", "/admin/c_surveysheet/selectinfo"}, //免权限检查路径
}

+ 5
- 9
conf/db.go View File

@ -13,15 +13,14 @@ type DbConf struct {
//线上服务器配置
var MasterDbConfig DbConf = DbConf{
Host: "localhost",
Port: 3306,
User: "root",
Pwd: "Leit2020",
Host: "101.201.121.115",
Port: 3306,
User: "root",
Pwd: "Lapp@123456",
DbName: "saisiwei",
BackUp: "C:\\Saisiwei\\dblog",
BackUp: "C:\\lappServer\\dblog",
}
//var MasterDbConfig DbConf = DbConf{
// Host: "127.0.0.1",
// Port: 3306,
@ -40,6 +39,3 @@ var MasterDbConfig DbConf = DbConf{
// DbName: "wyserver8094",
// BackUp: "C:\\ruifeng_wy\\dblog",
//}

+ 7
- 7
db/db.go View File

@ -1,15 +1,15 @@
package db
import (
"SSW_WebPlatform/conf"
"SSW_WebPlatform/utils"
"SSW_WebPlatform/web/middleware/glog"
"context"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"SSW_WebPlatform/conf"
"SSW_WebPlatform/utils"
"SSW_WebPlatform/web/middleware/glog"
"log"
"path/filepath"
"sync"
@ -39,9 +39,10 @@ func MasterEngine() *xorm.Engine {
c := conf.MasterDbConfig
driveSource := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
c.User, c.Pwd, c.Host, c.Port, c.DbName)
glog.InfoExtln("数据库信息", "driveSource:", driveSource)
engine, err := xorm.NewEngine(conf.DriverName, driveSource)
//开启sql,debug
//engine.ShowSQL(true)
engine.ShowSQL(true)
if err != nil {
log.Fatal("dbhelper.DbinstanceMaster error= ", err)
return nil
@ -77,7 +78,6 @@ func MgoDb() *mongo.Client {
}
}
//数据备份
func BackUp() {
var (
@ -98,8 +98,8 @@ func BackUp() {
} else {
glog.ErrorExtln("数据库连接成功:", "driveSource", driveSource)
}
filename := utils.TimeFormat(time.Now(),"yyyy-MM-dd") + ".sql"
dirpath := filepath.Join(c.BackUp,filename)
filename := utils.TimeFormat(time.Now(), "yyyy-MM-dd") + ".sql"
dirpath := filepath.Join(c.BackUp, filename)
err = engine.DumpAllToFile(dirpath, conf.DriverName)
if err != nil {
return


+ 2
- 2
main.go View File

@ -111,7 +111,7 @@ func imain() {
//数据备份
go db.CornTime()
//启动监听端口
app.Run(iris.Addr(":8090"), iris.WithConfiguration(parse.C))
//app.Run(iris.Addr(":8094"), iris.WithConfiguration(parse.C))
app.Run(iris.Addr(":8096"), iris.WithConfiguration(parse.C))
//app.Run(iris.Addr(":8096"), iris.WithConfiguration(parse.C))
}

+ 2
- 2
web/controllers/c_surveysheet_controller.go View File

@ -82,8 +82,8 @@ func GetCSurveysheetByUser(ctx iris.Context) {
me.Cnr, _ = ctx.URLParamInt("cid")
me.Surveysheetid = ctx.URLParam("surveysheetid")
level, _ := ctx.URLParamInt("level")
surveynr, _ := ctx.URLParamInt("surveynr")
result, err := me.SelectOneInfo(level, surveynr)
lastmodifyby := ctx.URLParam("userName")
result, err := me.SelectOneInfo(level, lastmodifyby)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return


+ 2
- 9
web/controllers/user_controller.go View File

@ -20,14 +20,7 @@ import (
func Login(ctx iris.Context) {
user := new(models.Usertab)
if err := ctx.ReadJSON(user); err != nil {
log := new(models.LeitServerLog)
log.File = "user_controller.go"
log.Level = "debug1"
log.Function = "Login"
log.Message = error.Error(err)
log.Operator = user.Userid
log.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
log.InsertRecord()
glog.InfoExtln("日志测试", "err:", err)
supports.Error(ctx, iris.StatusPaymentRequired, supports.LoginFailur, nil)
return
}
@ -60,7 +53,7 @@ func Login(ctx iris.Context) {
supports.Error(ctx, iris.StatusPaymentRequired, supports.UsernameFailur, nil)
return
}
glog.InfoExtln("密码", mUser.Password)
ckPassword, err := utils.CompareHashAndPassword(mUser.Password, user.Password)
if !ckPassword {
supports.Error(ctx, iris.StatusPaymentRequired, supports.PasswordFailur, nil)


+ 17
- 2
web/models/c_surveysheet.go View File

@ -24,6 +24,21 @@ type CSurveysheet struct {
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"`
CSurveysheetResult CSurveysheetResult `json:"cSurveysheetResult" xorm:"-"`
Valst []CSurveysheetSubjectlst `json:"valst" xorm:"-"`
AllPerson int `xorm:"-"`
A_Person int `xorm:"-"` //25岁以下
A_Per string `xorm:"-"` //25岁以下百分比
B_Person int `xorm:"-"` //25-35岁
B_Per string `xorm:"-"` //25-35岁 百分比
C_Person int `xorm:"-"` //35-45岁
C_Per string `xorm:"-"` //35-45岁 百分比
D_Person int `xorm:"-"` //45-55岁
D_Per string `xorm:"-"` //45-55岁百分比
E_Person int `xorm:"-"` //55岁以上
E_Per string `xorm:"-"` //55岁以上百分比
}
type Cvalst struct {
@ -437,7 +452,7 @@ func (t *CSurveysheet) SelectOne(level int) (CSurveysheet, error) {
}
//查卷子
func (t *CSurveysheet) SelectOneInfo(level, surveynr int) (CSurveysheet, error) {
func (t *CSurveysheet) SelectOneInfo(level int, lastmodifyby string) (CSurveysheet, error) {
e := db.MasterEngine()
var data CSurveysheet
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveysheetid}).Get(&data)
@ -445,7 +460,7 @@ func (t *CSurveysheet) SelectOneInfo(level, surveynr int) (CSurveysheet, error)
return data, err
}
//试卷头部
_, err = e.Table("c_surveysheet_result").Where("cid = ? and cnr = ? and surveysheetid = ? and surveynr = ?", t.Cid, t.Cnr, t.Surveysheetid, surveynr).Get(&data.CSurveysheetResult)
_, err = e.Table("c_surveysheet_result").Where("cid = ? and cnr = ? and surveysheetid = ? and lastmodifyby = ?", t.Cid, t.Cnr, t.Surveysheetid, lastmodifyby).Get(&data.CSurveysheetResult)
if err != nil {
return data, err
}


+ 27
- 0
web/models/c_surveysheet_result.go View File

@ -2174,6 +2174,33 @@ func (t *CSurveysheetResult) SurveysheetTotalBySheetId() (*CSurveysheet, error)
if !ok {
return nil, errors.New("没有该调查问卷信息!")
}
//统计年龄占比
resultList := make([]CSurveysheetResult, 0)
err = e.Table("c_surveysheet_result").Where("cid =? and surveysheetid = ?", t.Cid, subject.Surveysheetid).Find(&resultList)
if err != nil {
return nil, err
}
for _, v := range resultList {
subject.AllPerson += 1
if v.Age == 1 {
subject.A_Person += 1
} else if v.Age == 2 {
subject.B_Person += 1
} else if v.Age == 3 {
subject.C_Person += 1
} else if v.Age == 4 {
subject.D_Person += 1
} else if v.Age == 5 {
subject.E_Person += 1
}
}
if subject.Surveysamplecount > 0 {
subject.A_Per = fmt.Sprintf("%.2f", float64(subject.A_Person)/float64(subject.Surveysamplecount)*100)
subject.B_Per = fmt.Sprintf("%.2f", float64(subject.B_Person)/float64(subject.Surveysamplecount)*100)
subject.C_Per = fmt.Sprintf("%.2f", float64(subject.C_Person)/float64(subject.Surveysamplecount)*100)
subject.D_Per = fmt.Sprintf("%.2f", float64(subject.D_Person)/float64(subject.Surveysamplecount)*100)
subject.E_Per = fmt.Sprintf("%.2f", float64(subject.E_Person)/float64(subject.Surveysamplecount)*100)
}
//第二步:查询当前试卷的答题情况,并且做统计
answerData := make([]AnswerResult, 0)
err = e.Table("c_surveysheet_resultlst").Join("INNER", "c_surveysheet_result", "c_surveysheet_resultlst.cid = c_surveysheet_result.cid and c_surveysheet_resultlst.surveynr = c_surveysheet_result.surveynr and c_surveysheet_resultlst.surveysheetid = c_surveysheet_result.surveysheetid").Where("c_surveysheet_result.cid =? and c_surveysheet_resultlst.surveysheetid = ?", t.Cid, subject.Surveysheetid).Find(&answerData)


Loading…
Cancel
Save