初始
This commit is contained in:
@ -0,0 +1,123 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-10-07 17:11:20
|
||||
// 生成路径: internal/app/system/logic/bus_questions_configuration.go
|
||||
// 生成人:gfast
|
||||
// desc:题库配置
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusQuestionsConfiguration(New())
|
||||
}
|
||||
|
||||
func New() *sBusQuestionsConfiguration {
|
||||
return &sBusQuestionsConfiguration{}
|
||||
}
|
||||
|
||||
type sBusQuestionsConfiguration struct{}
|
||||
|
||||
func (s *sBusQuestionsConfiguration) List(ctx context.Context, req *system.BusQuestionsConfigurationSearchReq) (listRes *system.BusQuestionsConfigurationSearchRes, err error) {
|
||||
listRes = new(system.BusQuestionsConfigurationSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusQuestionsConfiguration.Ctx(ctx).WithAll()
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusQuestionsConfigurationInfoRes
|
||||
err = m.Fields(system.BusQuestionsConfigurationSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusQuestionsConfigurationListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusQuestionsConfigurationListRes{
|
||||
Id: v.Id,
|
||||
SingleChoice: v.SingleChoice,
|
||||
SingleScore: v.SingleScore,
|
||||
MultipleChoice: v.MultipleChoice,
|
||||
MultipleScore: v.MultipleScore,
|
||||
Estimate: v.Estimate,
|
||||
EstimateScore: v.EstimateScore,
|
||||
FullMark: v.FullMark,
|
||||
PassingScore: v.PassingScore,
|
||||
AnswerTime: v.AnswerTime,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuestionsConfiguration) GetById(ctx context.Context, id int64) (res *model.BusQuestionsConfigurationInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusQuestionsConfiguration.Ctx(ctx).WithAll().Where(dao.BusQuestionsConfiguration.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuestionsConfiguration) Add(ctx context.Context, req *system.BusQuestionsConfigurationAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusQuestionsConfiguration.Ctx(ctx).Insert(do.BusQuestionsConfiguration{
|
||||
SingleChoice: req.SingleChoice,
|
||||
SingleScore: req.SingleScore,
|
||||
MultipleChoice: req.MultipleChoice,
|
||||
MultipleScore: req.MultipleScore,
|
||||
Estimate: req.Estimate,
|
||||
EstimateScore: req.EstimateScore,
|
||||
FullMark: req.FullMark,
|
||||
PassingScore: req.PassingScore,
|
||||
AnswerTime: req.AnswerTime,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuestionsConfiguration) Edit(ctx context.Context, req *system.BusQuestionsConfigurationEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusQuestionsConfiguration.Ctx(ctx).WherePri(req.Id).Update(do.BusQuestionsConfiguration{
|
||||
SingleChoice: req.SingleChoice,
|
||||
SingleScore: req.SingleScore,
|
||||
MultipleChoice: req.MultipleChoice,
|
||||
MultipleScore: req.MultipleScore,
|
||||
Estimate: req.Estimate,
|
||||
EstimateScore: req.EstimateScore,
|
||||
FullMark: req.FullMark,
|
||||
PassingScore: req.PassingScore,
|
||||
AnswerTime: req.AnswerTime,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuestionsConfiguration) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusQuestionsConfiguration.Ctx(ctx).Delete(dao.BusQuestionsConfiguration.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user