|
@@ -0,0 +1,218 @@
|
|
|
+package cygx
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type CygxQuestionnaire struct {
|
|
|
+ QuestionnaireId int `orm:"column(questionnaire_id);pk"`
|
|
|
+ ActivityTypeId int `description:"活动类型id"`
|
|
|
+ ActivityTypeName string `description:"活动名称"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ EndTime time.Time `description:"截止日期"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+ PublishTime time.Time `description:"发布时间"`
|
|
|
+ AdminId int `description:"管理员ID"`
|
|
|
+ MaxChooseTotal int `description:"最多可选几项"`
|
|
|
+ OtherThemeTotal int `description:"其余主题投票数量"`
|
|
|
+}
|
|
|
+
|
|
|
+type CygxQuestionnaireTheme struct {
|
|
|
+ QuestionnaireThemeId int `orm:"column(questionnaire_theme_id);pk"`
|
|
|
+ QuestionnaireId int `description:"问卷ID"`
|
|
|
+ ActivityTheme string `description:"活动主题"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+}
|
|
|
+
|
|
|
+type AddCygxQuestionnaireReq struct {
|
|
|
+ QuestionnaireId int `description:"ID"`
|
|
|
+ ActivityTypeId int `description:"活动类型id"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ EndTime string `description:"截止日期"`
|
|
|
+ MaxChooseTotal int `description:"最多可选几项"`
|
|
|
+ ListTheme []*AddCygxQuestionnaireThemeReq
|
|
|
+}
|
|
|
+
|
|
|
+type AddCygxQuestionnaireThemeReq struct {
|
|
|
+ QuestionnaireThemeId int `description:"问卷主题ID"`
|
|
|
+ ActivityTheme string `description:"活动主题"`
|
|
|
+ VoteTotal int `description:"票数"`
|
|
|
+}
|
|
|
+
|
|
|
+type CygxQuestionnaireResp struct {
|
|
|
+ QuestionnaireId int `orm:"column(questionnaire_id);pk"`
|
|
|
+ ActivityTypeId int `description:"活动类型id"`
|
|
|
+ ActivityTypeName string `description:"活动类型名称"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ EndTime string `description:"截止日期"`
|
|
|
+ CreateTime string `description:"创建时间"`
|
|
|
+ ModifyTime string `description:"更新时间"`
|
|
|
+ PublishTime string `description:"发布时间"`
|
|
|
+ AdminId int `description:"管理员ID"`
|
|
|
+ MaxChooseTotal int `description:"最多可选几项"`
|
|
|
+ State string `description:"状态"`
|
|
|
+ OtherThemeTotal int `description:"其余主题投票数量"`
|
|
|
+ ListTheme []*AddCygxQuestionnaireThemeReq
|
|
|
+}
|
|
|
+
|
|
|
+type GetCygxQuestionnaireResp struct {
|
|
|
+ Paging *paging.PagingItem `description:"分页数据"`
|
|
|
+ List []*CygxQuestionnaireResp
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func AddCygxQuestionnaire(item *CygxQuestionnaire, listTheme []*AddCygxQuestionnaireThemeReq) (newId int64, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ to, err := o.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ newId, err = to.Insert(item)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range listTheme {
|
|
|
+ itemTheme := new(CygxQuestionnaireTheme)
|
|
|
+ itemTheme.QuestionnaireId = int(newId)
|
|
|
+ itemTheme.ActivityTheme = v.ActivityTheme
|
|
|
+ itemTheme.CreateTime = time.Now()
|
|
|
+ itemTheme.ModifyTime = time.Now()
|
|
|
+ _, err = to.Insert(itemTheme)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func EditCygxQuestionnaire(item *CygxQuestionnaire, listTheme []*AddCygxQuestionnaireThemeReq) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ to, err := o.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ updateParams["ActivityTypeId"] = item.ActivityTypeId
|
|
|
+ updateParams["ActivityTypeName"] = item.ActivityTypeName
|
|
|
+ updateParams["EndTime"] = item.EndTime
|
|
|
+ updateParams["ModifyTime"] = time.Now()
|
|
|
+ updateParams["MaxChooseTotal"] = item.MaxChooseTotal
|
|
|
+ updateParams["Content"] = item.Content
|
|
|
+ ptrStructOrTableName := "cygx_questionnaire"
|
|
|
+ whereParam := map[string]interface{}{"questionnaire_id": item.QuestionnaireId}
|
|
|
+ qs := to.QueryTable(ptrStructOrTableName)
|
|
|
+ for expr, exprV := range whereParam {
|
|
|
+ qs = qs.Filter(expr, exprV)
|
|
|
+ }
|
|
|
+ _, err = qs.Update(updateParams)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var questionnaireThemeIds []string
|
|
|
+ for _, v := range listTheme {
|
|
|
+ questionnaireThemeIds = append(questionnaireThemeIds, strconv.Itoa(v.QuestionnaireThemeId))
|
|
|
+ }
|
|
|
+ sql := ` DELETE FROM cygx_questionnaire_theme WHERE questionnaire_id = ? AND questionnaire_theme_id NOT IN (` + strings.Join(questionnaireThemeIds, ",") + `)`
|
|
|
+ _, err = to.Raw(sql, item.QuestionnaireId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range listTheme {
|
|
|
+ if v.QuestionnaireThemeId == 0 {
|
|
|
+ itemTheme := new(CygxQuestionnaireTheme)
|
|
|
+ itemTheme.QuestionnaireId = item.QuestionnaireId
|
|
|
+ itemTheme.ActivityTheme = v.ActivityTheme
|
|
|
+ itemTheme.CreateTime = time.Now()
|
|
|
+ itemTheme.ModifyTime = time.Now()
|
|
|
+ _, err = to.Insert(itemTheme)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ updateParams["ActivityTheme"] = v.ActivityTheme
|
|
|
+ updateParams["ModifyTime"] = time.Now()
|
|
|
+ ptrStructOrTableName := "cygx_questionnaire_theme"
|
|
|
+ whereParam := map[string]interface{}{"questionnaire_theme_id": v.QuestionnaireThemeId}
|
|
|
+ qs := to.QueryTable(ptrStructOrTableName)
|
|
|
+ for expr, exprV := range whereParam {
|
|
|
+ qs = qs.Filter(expr, exprV)
|
|
|
+ }
|
|
|
+ _, err = qs.Update(updateParams)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GetCygxQuestionnaireCount(condition string, pars []interface{}) (count int, err error) {
|
|
|
+ sqlCount := ` SELECT COUNT(1) AS count FROM cygx_questionnaire as art WHERE 1= 1 `
|
|
|
+ if condition != "" {
|
|
|
+ sqlCount += condition
|
|
|
+ }
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ err = o.Raw(sqlCount, pars).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GetCygxQuestionnaireList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxQuestionnaireResp, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ sql := `SELECT * FROM cygx_questionnaire as art WHERE 1= 1 `
|
|
|
+ if condition != "" {
|
|
|
+ sql += condition
|
|
|
+ }
|
|
|
+ sql += ` LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type GetCygxQuestionnaireDetailResp struct {
|
|
|
+ Detail *CygxQuestionnaireResp
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GetCygxQuestionnaireDetail(questionnaireId int) (item *CygxQuestionnaireResp, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ sql := `SELECT * FROM cygx_questionnaire WHERE questionnaire_id=? `
|
|
|
+ err = o.Raw(sql, questionnaireId).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GetCygxQuestionnaireThemeListByQuestionnaireId(questionnaireId int) (items []*AddCygxQuestionnaireThemeReq, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ sql := `SELECT * FROM cygx_questionnaire_theme as art WHERE questionnaire_id = ? `
|
|
|
+ _, err = o.Raw(sql, questionnaireId).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|