Browse Source

Merge branch 'develop' of http://101.201.121.115:3000/leo/SSW_WebPlatform into feature_alg

pull/4/head
zhangxin 3 years ago
parent
commit
21791ca108
8 changed files with 1151 additions and 59 deletions
  1. +107
    -5
      web/controllers/c_surveysheet_controller.go
  2. +4
    -5
      web/controllers/c_surveysheet_result_controller.go
  3. +37
    -4
      web/models/c_surveysheet.go
  4. +877
    -31
      web/models/c_surveysheet_result.go
  5. +4
    -4
      web/models/c_surveysheet_subjectlst.go
  6. +118
    -8
      web/models/statistic.go
  7. +2
    -1
      web/routes/routes.go
  8. +2
    -1
      web/supports/vo/userVO.go

+ 107
- 5
web/controllers/c_surveysheet_controller.go View File

@ -1,12 +1,13 @@
package controllers
import (
"github.com/kataras/iris/v12"
"SSW_WebPlatform/utils"
"SSW_WebPlatform/web/middleware/glog"
"SSW_WebPlatform/web/middleware/jwts"
"SSW_WebPlatform/web/models"
"SSW_WebPlatform/web/supports"
"github.com/kataras/iris/v12"
"strings"
"time"
)
@ -75,6 +76,64 @@ func GetCSurveysheet(ctx iris.Context) {
supports.Ok(ctx, supports.OptionSuccess, result)
}
func GetCSurveysheetByUser(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
me := new(models.CSurveysheet)
me.Cid, _ = ctx.URLParamInt("cid")
me.Cnr, _ = ctx.URLParamInt("cid")
me.Lastmodifyby = ctx.URLParam("userName")
me.Surveysheetid = ctx.URLParam("surveysheetid")
level, _ := ctx.URLParamInt("level")
result, err := me.SelectOneInfo(level)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
//根据用户查询答案
userResult := new(models.CSurveysheetResult)
userResult.Cid, _ = ctx.URLParamInt("cid")
userResult.Lastmodifyby = ctx.URLParam("userName")
userResult.Surveysheetid = ctx.URLParam("surveysheetid")
data, err := userResult.SurveysheetSearchByUser()
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
cache := make(map[string][]models.CSurveysheetResultlst)
for _, v := range data {
key := strings.TrimSpace(v.Subjectid)
value := v
cache[key] = append(cache[key], value)
}
for kk, vv := range result.Valst {
key := strings.TrimSpace(vv.Subjectid)
val, ok := cache[key]
if ok {
if len(val) > 0 {
var SelectedOptions []string
var Subjectid string
var Optioninput string
for _, v := range val {
Subjectid = v.Subjectid
Optioninput = v.Optioninput
SelectedOptions = append(SelectedOptions, v.SelectedOptions)
}
Options := strings.Join(SelectedOptions, ",")
result.Valst[kk].QuestionNaireItem.Subjectid = Subjectid
result.Valst[kk].QuestionNaireItem.Optioninput = Optioninput
result.Valst[kk].QuestionNaireItem.Selected_options = Options
}
}
}
supports.Ok(ctx, supports.OptionSuccess, result)
}
func InsertCSurveysheet(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
@ -185,7 +244,7 @@ func SelectArrCSurveysheet(ctx iris.Context) {
return
}
me := new(models.CSurveysheet)
me.Cid = user.Pid
//me.Cid = user.Pid
result, err := me.SelectArr()
if err != nil {
@ -195,7 +254,6 @@ func SelectArrCSurveysheet(ctx iris.Context) {
supports.Ok(ctx, supports.OptionSuccess, result)
}
func StatisticData(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
@ -203,10 +261,54 @@ func StatisticData(ctx iris.Context) {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
me := new(models.CSurveysheetResult)
selectType := ctx.URLParam("selectType")
me.Cid = user.Pid
result, err := me.Statistic(selectType)
if user.Role == "group" || user.Role == "admin" {
cid, _ := ctx.URLParamInt("cid")
if cid < 0 {
me.Cid = user.Pid
} else {
me.Cid, _ = ctx.URLParamInt("cid")
}
} else {
me.Cid = user.Pid
}
year := ctx.URLParam("year")
if utils.ValueIsEmpty(year) {
supports.Error(ctx, iris.StatusBadRequest, "参数不能空!", nil)
return
}
unit := ctx.URLParam("unit")
result, err := me.Statistic(selectType, year, unit)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, result)
}
//集团用户查看对比
func AllStatisticData(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
me := new(models.CSurveysheetResult)
selectType := ctx.URLParam("selectType")
year := ctx.URLParam("year")
if utils.ValueIsEmpty(year) {
supports.Error(ctx, iris.StatusBadRequest, "参数不能空!", nil)
return
}
unit := ctx.URLParam("unit")
cidStr := ctx.URLParam("cids")
cids := strings.Split(cidStr, ",")
result, err := me.AllStatistic(selectType, cids, year, unit)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)


+ 4
- 5
web/controllers/c_surveysheet_result_controller.go View File

@ -28,19 +28,18 @@ func InsertCSurveysheetResult(ctx iris.Context) {
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
data := new(models.CSurveysheetResult)
data.Lastmodifyby = user.Userid
data.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
data.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
data.Cid = user.Pid
if err := ctx.ReadJSON(data); err != nil {
supports.Error(ctx, iris.StatusBadRequest, "json解析错误", nil)
return
}
data.Lastmodifyby = user.Userid
data.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
data.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
data.Cid = user.Pid
err := data.Add()
if err != nil {
glog.InfoExt("问题调研", "add err is :", err)
supports.Error(ctx, iris.StatusBadRequest, "添加失败!", nil)
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, "")


+ 37
- 4
web/models/c_surveysheet.go View File

@ -21,8 +21,8 @@ type CSurveysheet struct {
Createtime string `json:"createtime" xorm:"default 'NULL' comment('创建时间') VARCHAR(40)"`
Lastmodifytime string `json:"lastmodifytime" xorm:"default 'NULL' comment('最近更新时间') VARCHAR(40)"`
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"`
CSurveysheetResult CSurveysheetResult `json:"cSurveysheetResult" xorm:"-"`
Valst []CSurveysheetSubjectlst `json:"valst" xorm:"-"`
}
type Cvalst struct {
@ -435,6 +435,40 @@ func (t *CSurveysheet) SelectOne(level int) (CSurveysheet, error) {
return data, nil
}
//查卷子
func (t *CSurveysheet) SelectOneInfo(level int) (CSurveysheet, error) {
e := db.MasterEngine()
var data CSurveysheet
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveysheetid}).Get(&data)
if err != nil {
return data, err
}
//试卷头部
_, err = e.Table("c_surveysheet_result").Where("cid = ? and cnr = ? and surveysheetid = ? and lastmodifyby = ?",t.Cid, t.Cnr, t.Surveysheetid,t.Lastmodifyby).Get(&data.CSurveysheetResult)
if err != nil {
return data, err
}
datalist := make([]CSurveysheetSubjectlst, 0)
if level > 0 {
err = e.Table("c_surveysheet_subjectlst").Where("cid = ? and cnr = ? and surveysheetid = ? and level != 1", t.Cid, t.Cnr, t.Surveysheetid).Asc("pos").Find(&datalist)
} else {
err = e.Table("c_surveysheet_subjectlst").Where("cid = ? and cnr = ? and surveysheetid = ?", t.Cid, t.Cnr, t.Surveysheetid).Asc("pos").Find(&datalist)
}
if err != nil {
return data, err
}
for k, v := range datalist {
list := make([]CSurveysheetOptionlst, 0)
err = e.Table("c_surveysheet_optionlst").Where("cid = ? and cnr = ? and surveysheetid = ? and subjectid = ?", t.Cid, t.Cnr, t.Surveysheetid, v.Subjectid).Find(&list)
if err != nil {
return data, err
}
datalist[k].Valst = list
}
data.Valst = datalist
return data, nil
}
//查卷子
func (t *CSurveysheet) WxSelectOne() (CSurveysheet, error) {
e := db.MasterEngine()
@ -488,14 +522,13 @@ func (t *CSurveysheet) GetPage(pageSize int, pageIndex int) ([]CSurveysheet, int
//查询调研问卷
func (t *CSurveysheet) SelectArr() (data []CSurveysheet, err error) {
e := db.MasterEngine()
err = e.Table("c_surveysheet").Where("cid = ?", t.Cid).Find(&data)
err = e.Table("c_surveysheet").Find(&data)
if err != nil {
return data, err
}
return data, nil
}
//查卷子信息
func (t *CSurveysheet) SelectInfo() (CSurveysheet, error) {
e := db.MasterEngine()
@ -505,4 +538,4 @@ func (t *CSurveysheet) SelectInfo() (CSurveysheet, error) {
return data, err
}
return data, nil
}
}

+ 877
- 31
web/models/c_surveysheet_result.go
File diff suppressed because it is too large
View File


+ 4
- 4
web/models/c_surveysheet_subjectlst.go View File

@ -26,8 +26,8 @@ func (t *CSurveysheetSubjectlst) TableName() string {
}
type QuestionNaireItem struct {
Subjectid string `json:"subjectid"`
Optioninput string `json:"optioninput"`
Optiontext string `json:"optiontext"`
Selected_options string `json:"selected_options"`
Subjectid string `json:"subjectid"`
Optioninput string `json:"optioninput"`
Optiontext string `json:"optiontext"`
Selected_options string `json:"selected_options"`
}

+ 118
- 8
web/models/statistic.go View File

@ -299,14 +299,14 @@ type PicTotal struct {
}
type StatisticData struct {
Total TotalStatisticData `json:"total"`
PicTotal PicTotal `json:"picTotal"`
RecentYears []RecentYear `json:"recentYears"`
Time []TimeStatisticData `json:"time"`
Cate []CateStatisticData `json:"cate"`
Building BuildingData `json:"building"`
BuildingCate []BuildingCate `json:"buildingCate"`
YearCate []YearStatisticData `json:"yearCate"`
Total TotalStatisticData `json:"total"` //饼图
PicTotal PicTotal `json:"picTotal"` //图片统计
RecentYears []RecentYear `json:"recentYears"` //按年统计
Time []TimeStatisticData `json:"time"` //各阶段业主调研样本量
Cate []CateStatisticData `json:"cate"` //各项满意度数据统计
Building BuildingData `json:"building"` //各楼栋具体取样情况
BuildingCate []BuildingCate `json:"buildingCate"` //各楼栋满意度排名表
YearCate []YearStatisticData `json:"yearCate"` //按年统计带分类
}
type TotalStatisticData struct {
@ -324,6 +324,116 @@ type TotalStatisticData struct {
SatisfactionPercent float64 `json:"satisfactionPercent"`
}
// 分类园区统计数据
type CidStatisticData struct {
SubjectStaticDataLi []SubjectStaticData `json:"subjectStaticDataLi"`
Cid string `json:"cid"` //项目id
CidName string `json:"cidName"` //项目名称
Cate string `json:"subject_categoryid"`
ASum int `json:"aSum"`
APercent float64 `json:"aPercent"`
BSum int `json:"bSum"`
BPercent float64 `json:"bPercent"`
CSum int `json:"cSum"`
CPercent float64 `json:"cPercent"`
DSum int `json:"dSum"`
DPercent float64 `json:"dPercent"`
ESum int `json:"eSum"`
EPercent float64 `json:"ePercent"`
ActPersons int `json:"actPersons"`
Count int `json:"count"`
SatisfactionPercent float64 `json:"per_total"`
}
func (cid CidStatisticData) Compare(iData interface{}) int {
data, ok := iData.(CidStatisticData)
if !ok {
return -2
}
if cid.SatisfactionPercent < data.SatisfactionPercent {
return 1
}
if cid.SatisfactionPercent == data.SatisfactionPercent {
return 0
}
return -1
}
type GatherStatisticData struct {
GatherTotal []CidStatisticData `json:"gatherTotal"` //集团单项满意度汇总
GatherProjectTotalPer []GatherTotalStatisticData `json:"gatherProjectTotalPer"` //满意度评比表
ItemDataTotalGather []ItemDataTotalGather `json:"itemDataTotalGather"` //满意度评比表
}
//集团单项满意度汇总
type GatherTotal struct {
Cid string `json:"cid"` //项目id
CidName string `json:"cidName"` //项目名称
ActPersons int `json:"actPersons"` //采集人数
AllPer float64 `json:"allPer"` //整体满意度
Items map[string]float64 `json:"items"`
}
//满意度评比表
type GatherTotalStatisticData struct {
Cid string `json:"cid"` //项目id
CidName string `json:"cidName"` //项目名称
SumTotal int `json:"sumTotal"` //总户数
ActPersons int `json:"actPersons"` //采集人数
ActPer float64 `json:"actPer"` //采集比例
ASum int `json:"aSum"`
APercent float64 `json:"aPercent"`
BSum int `json:"bSum"`
BPercent float64 `json:"bPercent"`
CSum int `json:"cSum"`
CPercent float64 `json:"cPercent"`
DSum int `json:"dSum"`
DPercent float64 `json:"dPercent"`
ESum int `json:"eSum"`
EPercent float64 `json:"ePercent"`
Count int `json:"count"`
SatisfactionPersons int `json:"satisfactionPersons"`
SatisfactionPercent float64 `json:"satisfactionPercent"`
}
func (g GatherTotalStatisticData) Compare(iData interface{}) int {
data, ok := iData.(GatherTotalStatisticData)
if !ok {
return -2
}
if g.SatisfactionPercent < data.SatisfactionPercent {
return 1
}
if g.SatisfactionPercent == data.SatisfactionPercent {
return 0
}
return -1
}
//各项满意度
type ItemDataTotalGather struct {
SubjectCategoryid string `json:"subject_categoryid"`
ItemInfo []ItemInfo `json:"itemInfo"`
}
func (item ItemInfo) Compare(iData interface{}) int {
data, ok := iData.(ItemInfo)
if !ok {
return -2
}
if item.SatisfactionPercent < data.SatisfactionPercent {
return 1
}else {
return -1
}
}
type ItemInfo struct {
Cid string `json:"cid"` //项目id
CidName string `json:"cidName"` //项目名称
SatisfactionPercent float64 `json:"satisfactionPercent"` //满意度
}
func BubbleSort(list []ICompare) []ICompare {
for i := 0; i < len(list); i++ {
for j := 1; j < len(list)-i; j++ {


+ 2
- 1
web/routes/routes.go View File

@ -144,6 +144,7 @@ func Hub(app *iris.Application) {
c_surveysheet.Put("/upinfo", controllers.UpdateCSurveysheet)
c_surveysheet.Post("/addinfo", controllers.InsertCSurveysheet)
c_surveysheet.Delete("/del", controllers.DeleteCSurveysheet)
c_surveysheet.Get("/selectresultbyuser", controllers.GetCSurveysheetByUser)
//用户答题
c_surveysheet_result := admin.Party("/c_surveysheet_result")
@ -152,7 +153,7 @@ func Hub(app *iris.Application) {
c_surveysheet_result.Get("/totalmultiple", controllers.TotalMultipleCSurveysheetResult)
c_surveysheet_result.Get("/selectarr", controllers.SelectArrCSurveysheet)
c_surveysheet_result.Get("/statistic", controllers.StatisticData)
c_surveysheet_result.Get("/allstatistic", controllers.AllStatisticData)
}
// 权限API模块


+ 2
- 1
web/supports/vo/userVO.go View File

@ -9,7 +9,7 @@ type UserVO struct {
Pid int `json:"pid" form:"pid"`
Userid string `json:"userid" form:"userid"`
Enable int `json:"enable"`
Appid string `json:"appid" form:"appid"`
Role string `json:"role"`
Name string `json:"name" form:"name"`
Phone string `json:"phone" form:"phone"`
Email string `json:"email" form:"email"`
@ -26,6 +26,7 @@ func TansformUserVO(token string, user *models.Usertab) (uVO UserVO) {
uVO.Name = user.Name
uVO.Phone = user.Phone
uVO.Email = user.Email
uVO.Role = user.Role
uVO.Token = token


Loading…
Cancel
Save