| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package learning
- import (
- "context"
- "encoding/base64"
- "lims_adapter/model"
- "lims_adapter/model/learning"
- learningSrv "lims_adapter/service/learning"
- "dashoo.cn/common_definition/comm_def"
- "dashoo.cn/micro_libary/myerrors"
- "github.com/gogf/gf/frame/g"
- )
- type LearningQuestion struct{}
- func (c *LearningQuestion) List(ctx context.Context, req *learning.LearningQuestionListReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.List request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- total, ent, err := s.List(ctx, req)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- if ent == nil {
- ent = []*learning.LearningQuestionGetRsp{}
- }
- rsp.Code = code
- rsp.Msg = msg
- rsp.Data = map[string]interface{}{
- "total": total,
- "list": ent,
- }
- return nil
- }
- func (c *LearningQuestion) Get(ctx context.Context, req *learning.LearningQuestionGetReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Get request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- ent, err := s.Get(ctx, req)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Code = code
- rsp.Msg = msg
- rsp.Data = ent
- return nil
- }
- func (c *LearningQuestion) Add(ctx context.Context, req *learning.LearningQuestionAddReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Add request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- id, err := s.Add(ctx, req)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Code = code
- rsp.Msg = msg
- rsp.Data = id
- return nil
- }
- func (c *LearningQuestion) Update(ctx context.Context, req *learning.LearningQuestionUpdateReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Update request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- err = s.Update(ctx, req)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Code = code
- rsp.Msg = msg
- return nil
- }
- func (c *LearningQuestion) Delete(ctx context.Context, req *learning.LearningQuestionDeleteReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Delete request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- err = s.Delete(ctx, req.Id)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Code = code
- rsp.Msg = msg
- return nil
- }
- func (c *LearningQuestion) Template(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Template request %#v ", *req)
- f, err := learningSrv.QuestionTemplate()
- if err != nil {
- return err
- }
- buf, err := f.WriteToBuffer()
- if err != nil {
- return err
- }
- rsp.Code = 200
- rsp.Data = base64.StdEncoding.EncodeToString(buf.Bytes())
- return nil
- }
- func (c *LearningQuestion) BatchUpload(ctx context.Context, req *learning.LearningQuestionBatchUploadReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("LearningQuestion.Delete request %#v ", *req)
- s, err := learningSrv.NewLearningQuestionService(ctx)
- if err != nil {
- return err
- }
- err = s.BatchUpload(ctx, req)
- _, err, code, msg := myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Code = code
- rsp.Msg = msg
- return nil
- }
|