Преглед изворни кода

feature:培训考试考试记录管理

liuyaqi пре 3 година
родитељ
комит
a1fc96edec
5 измењених фајлова са 419 додато и 0 уклоњено
  1. 90 0
      handler/learning/exam_record.go
  2. 2 0
      main.go
  3. 22 0
      model/learning/learning_exam_record.go
  4. 130 0
      service/learning/exam_record.go
  5. 175 0
      swaggerui/swagger.yml

+ 90 - 0
handler/learning/exam_record.go

@@ -0,0 +1,90 @@
+package learning
+
+import (
+	"context"
+	"fmt"
+	"lims_adapter/model/learning"
+	learningSrv "lims_adapter/service/learning"
+
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"github.com/gogf/gf/frame/g"
+)
+
+type LearningExamRecord struct{}
+
+func (c *LearningExamRecord) List(ctx context.Context, req *learning.LearningExamRecordListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningExamRecord.List request %v ", &req)
+	s, err := learningSrv.NewLearningExamRecordService(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.LearningExamRecordGetRsp{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+func (c *LearningExamRecord) ListMy(ctx context.Context, req *learning.LearningExamRecordListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningExamRecord.List request %v ", &req)
+	s, err := learningSrv.NewLearningExamRecordService(ctx)
+	if err != nil {
+		return err
+	}
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+
+	req.UserId = int(userInfo.Id)
+	total, ent, err := s.List(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*learning.LearningExamRecordGetRsp{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+func (c *LearningExamRecord) AddToMy(ctx context.Context, req *learning.LearningExamRecordAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningExamRecord.AddToMy request %v ", &req)
+	s, err := learningSrv.NewLearningExamRecordService(ctx)
+	if err != nil {
+		return err
+	}
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+
+	req.UserId = int(userInfo.Id)
+	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
+}

+ 2 - 0
main.go

@@ -62,6 +62,8 @@ func main() {
 		new((learning.LearningMaterial)), "")
 	s.RegisterName("LearningQuestion",
 		new((learning.LearningQuestion)), "")
+	s.RegisterName("LearningExamRecord",
+		new((learning.LearningExamRecord)), "")
 
 	// 注册auth处理
 	s.AuthFunc = handleAuth

+ 22 - 0
model/learning/learning_exam_record.go

@@ -5,6 +5,7 @@
 package learning
 
 import (
+	"lims_adapter/model"
 	"lims_adapter/model/learning/internal"
 )
 
@@ -12,3 +13,24 @@ import (
 type LearningExamRecord internal.LearningExamRecord
 
 // Fill with you ideas below.
+type LearningExamRecordListReq struct {
+	Page        *model.Page    `json:"page"`
+	OrderBy     *model.OrderBy `json:"orderBy"`
+	UserId      int            `json:"userId"`      // 用户 Id
+	SkillId     int            `json:"skillId"`     // 技能 Id
+	TestpaperId int            `json:"testpaperId"` // 试卷 Id
+	Status      int            `json:"status"`      // 状态 1 通过 2 未通过
+}
+
+type LearningExamRecordGetRsp struct {
+	LearningExamRecord
+	UserName  string `json:"userName"`  // 用户名称
+	SkillName string `json:"skillName"` // 技能名称
+}
+
+type LearningExamRecordAddReq struct {
+	UserId      int `json:"userId" v:"required#请输入用户Id"`                 // 用户 Id
+	SkillId     int `json:"skillId" v:"required#请输入技能Id"`                // 技能 Id
+	TestpaperId int `json:"testpaperId" v:"required#请输入试卷Id"`            // 试卷 Id
+	Status      int `json:"status" v:"required#请输入状态 in:1,2#请输入正确的状态类型"` // 状态 1 通过 2 未通过
+}

+ 130 - 0
service/learning/exam_record.go

@@ -0,0 +1,130 @@
+package learning
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"lims_adapter/dao/learning"
+	"lims_adapter/model/learning"
+
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"dashoo.cn/micro_libary/request"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type LearningExamRecordService struct {
+	Dao      *dao.LearningExamRecordDao
+	Tenant   string
+	userInfo request.UserInfo
+}
+
+func NewLearningExamRecordService(ctx context.Context) (*LearningExamRecordService, error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取组合码异常:%s", err.Error())
+	}
+	// 获取用户信息
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+	return &LearningExamRecordService{
+		Dao:      dao.NewLearningExamRecordDao(tenant),
+		Tenant:   tenant,
+		userInfo: userInfo,
+	}, nil
+}
+
+func (s LearningExamRecordService) List(ctx context.Context, req *learning.LearningExamRecordListReq) (int, []*learning.LearningExamRecordGetRsp, error) {
+	m := s.Dao.DB.
+		Table("learning_exam_record a").
+		LeftJoin("learning_skill b", "a.SkillId=b.Id").
+		LeftJoin("base_user c", "a.SkillId=b.Id").
+		Fields("a.*", "b.Name as SkillName", "c.Realname as UserName")
+	if req.UserId != 0 {
+		m = m.Where("UserId = ?", req.UserId)
+	}
+	if req.SkillId != 0 {
+		m = m.Where("SkillId = ?", req.SkillId)
+	}
+	if req.TestpaperId != 0 {
+		m = m.Where("TestpaperId = ?", req.TestpaperId)
+	}
+	if req.Status != 0 {
+		m = m.Where("Status = ?", req.Status)
+	}
+	total, err := m.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+
+	if req.Page != nil {
+		if req.Page.Current == 0 {
+			req.Page.Current = 1
+		}
+		if req.Page.Size == 0 {
+			req.Page.Size = 10
+		}
+		m = m.Page(req.Page.Current, req.Page.Size)
+	}
+	if req.OrderBy != nil && req.OrderBy.Value != "" {
+		order := "asc"
+		if req.OrderBy.Type == "desc" {
+			order = "desc"
+		}
+		m = m.Order(req.OrderBy.Value, order)
+	}
+
+	records := []*learning.LearningExamRecordGetRsp{}
+	err = m.Structs(&records)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	return total, records, err
+}
+
+func (s LearningExamRecordService) Add(ctx context.Context, req *learning.LearningExamRecordAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, validErr.Current()
+	}
+	if req.UserId != 0 {
+		r, err := s.Dao.DB.Table("base_user").Where("Id = ?", req.UserId).One()
+		if err != nil {
+			return 0, err
+		}
+		if r.IsEmpty() {
+			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("用户不存在: %d", req.UserId))
+		}
+	}
+	if req.SkillId != 0 {
+		r, err := s.Dao.DB.Table("learning_skill").Where("Id = ?", req.SkillId).One()
+		if err != nil {
+			return 0, err
+		}
+		if r.IsEmpty() {
+			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
+		}
+	}
+	if req.TestpaperId != 0 {
+		r, err := s.Dao.DB.Table("learning_testpaper").Where("Id = ?", req.TestpaperId).One()
+		if err != nil {
+			return 0, err
+		}
+		if r.IsEmpty() {
+			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("试卷不存在: %d", req.TestpaperId))
+		}
+	}
+
+	id, err := s.Dao.InsertAndGetId(learning.LearningExamRecord{
+		UserId:      req.UserId,
+		SkillId:     req.SkillId,
+		TestpaperId: req.TestpaperId,
+		Status:      req.Status,
+		CreatedAt:   gtime.Now(),
+		UpdatedAt:   gtime.Now(),
+	})
+	return int(id), err
+}

+ 175 - 0
swaggerui/swagger.yml

@@ -405,6 +405,81 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningExamRecord.AddToMy:
+      post:
+        tags:
+          - 考试培训-考试记录
+        operationId: LearningExamRecordAddToMy
+        summary: 添加考试记录
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningExamRecordAddToMy'
+              examples:
+                LearningExamRecordAddToMy:
+                  $ref: '#/components/examples/LearningExamRecordAddToMy'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningExamRecord.ListMy:
+      post:
+        tags:
+          - 考试培训-考试记录
+        operationId: LearningExamRecordListMy
+        summary: 查询我的考试记录
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningExamRecordListMy'
+              examples:
+                LearningExamRecordListMy:
+                  $ref: '#/components/examples/LearningExamRecordListMy'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningExamRecord.List:
+      post:
+        tags:
+          - 考试培训-考试记录
+        operationId: LearningExamRecordList
+        summary: 查询考试记录
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningExamRecordList'
+              examples:
+                LearningExamRecordList:
+                  $ref: '#/components/examples/LearningExamRecordList'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
 # 添加这个 swagger ui 会显示授权按钮
 security:
   - bearerAuth: []
@@ -731,6 +806,95 @@ components:
         explanationImage:
           type: string
           description: 题目解析图片
+    LearningExamRecordAddToMy:
+      type: object
+      required:
+        - skillId
+        - testpaperId
+        - status
+      properties:
+        skillId:
+          type: integer
+          description: 技
+        testpaperId:
+          type: integer
+          description: 试
+        status:
+          type: integer
+          description: 状态 1 通过 2 未通过
+    LearningExamRecordListMy:
+      type: object
+      properties:
+        page:
+          type: object
+          description: 分页信息,不传默认不分页,返回所有数据
+          properties:
+            current:
+              type: integer
+              description: 当前页面
+            size:
+              type: integer
+              description: 每页条数
+        orderBy:
+          type: object
+          description: 排序
+          properties:
+            type:
+              type: string
+              description: 排序方式
+              enum:
+                - asc
+                - desc
+            value:
+              type: string
+              description: 字段名
+        skillId:
+          type: integer
+          description: 技
+        testpaperId:
+          type: integer
+          description: 试
+        status:
+          type: integer
+          description: 状态 1 通过 2 未通过
+    LearningExamRecordList:
+      type: object
+      properties:
+        page:
+          type: object
+          description: 分页信息,不传默认不分页,返回所有数据
+          properties:
+            current:
+              type: integer
+              description: 当前页面
+            size:
+              type: integer
+              description: 每页条数
+        orderBy:
+          type: object
+          description: 排序
+          properties:
+            type:
+              type: string
+              description: 排序方式
+              enum:
+                - asc
+                - desc
+            value:
+              type: string
+              description: 字段名
+        skillId:
+          type: integer
+          description: 技
+        testpaperId:
+          type: integer
+          description: 试
+        status:
+          type: integer
+          description: 状态 1 通过 2 未通过
+        userId:
+          type: integer
+          description: 用户 Id
 
   examples:
     success:
@@ -874,3 +1038,14 @@ components:
     LearningQuestionDelete:
       value:
         id: 1
+    LearningExamRecordAddToMy:
+      value:
+        skillId: 2
+        testpaperId: 2
+        status: 2
+    LearningExamRecordListMy:
+      value:
+        skillId: 2
+    LearningExamRecordList:
+      value:
+        skillId: 2