123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package eta_trial
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type EtaTrialQuestionnaire struct {
- QuestionnaireId int `orm:"column(questionnaire_id);pk" description:"问卷题目id"`
- Question string `description:"题目"`
- Options string `description:"选项"`
- Type int `description:"1单选 2多选 3简答题"`
- Sort int `description:"排序"`
- IsMust int `description:"是否必填"`
- CreateTime time.Time
- }
- // Update
- func (item *EtaTrialQuestionnaire) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- // AddEtaTrialQuestionnaire
- func AddEtaTrialQuestionnaire(questionnaire *EtaTrialQuestionnaire) (err error) {
- o := orm.NewOrm()
- id, err := o.Insert(questionnaire)
- if err != nil {
- return
- }
- questionnaire.QuestionnaireId = int(id)
- return
- }
- func GetETATrialQuestionnaireList(cond string) (items []*EtaTrialQuestionnaire, err error) {
- sql := `SELECT * FROM eta_trial_questionnaire AS a WHERE 1=1 `
- o := orm.NewOrm()
- if cond != "" {
- sql += cond
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type EtaTrialQuestionnaireRespItem struct {
- QuestionnaireId int `orm:"column(questionnaire_id);pk" description:"问卷题目id"`
- Question string `description:"题目"`
- Type int `description:"1单选 2多选 3简答题"`
- Sort int `description:"排序"`
- Options []string `description:"选项"`
- IsMust int `description:"是否必填"`
- CreateTime string
- }
- type EtaTrialQuestionnaireResp struct {
- List []EtaTrialQuestionnaireRespItem
- }
- type EtaTrialQuestionnaireSaveReq struct {
- List []EtaTrialQuestionnaireSaveItem
- }
- type EtaTrialQuestionnaireSaveItem struct {
- QuestionnaireId int ` description:"问卷题目id"`
- Question string `description:"题目"`
- Options []string `description:"选项"`
- Sort int `description:"排序"`
- IsMust int `description:"是否必填 0是 1不是"`
- Type int `description:"1单选 2多选 3简答题"`
- }
- type EtaTrialQuestionnaireDelReq struct {
- QuestionnaireId int `description:"问卷题目id"`
- }
- func GetETATrialQuestionnaireById(qId int) (count int, err error) {
- sql := `SELECT count(1) AS count FROM eta_trial_questionnaire WHERE questionnaire_id = ? `
- o := orm.NewOrm()
- err = o.Raw(sql, qId).QueryRow(&count)
- return
- }
- func DelETATrialQuestionnaireById(qId int) (err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- //删问题
- sql := `DELETE FROM eta_trial_questionnaire WHERE questionnaire_id = ? `
- _, err = to.Raw(sql, qId).Exec()
- if err != nil {
- return
- }
- //删选项
- sql = `DELETE FROM eta_trial_questionnaire_options WHERE questionnaire_id = ? `
- _, err = to.Raw(sql, qId).Exec()
- if err != nil {
- return
- }
- //删记录
- sql = `DELETE FROM eta_trial_questionnaire_record WHERE questionnaire_id = ? `
- _, err = to.Raw(sql, qId).Exec()
- if err != nil {
- return
- }
- return
- }
- func AddETATrialQuestionnaire(questions []*EtaTrialQuestionnaire) (err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- //新增问题
- _, tmpErr := to.InsertMulti(len(questions), questions)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- return
- }
- func (m EtaTrialQuestionnaireResp) Len() int {
- return len(m.List)
- }
- func (m EtaTrialQuestionnaireResp) Less(i, j int) bool {
- return m.List[i].Sort < m.List[j].Sort
- }
- func (m EtaTrialQuestionnaireResp) Swap(i, j int) {
- m.List[i], m.List[j] = m.List[j], m.List[i]
- }
|