6
0
Prechádzať zdrojové kódy

feature:添培训考试的技能模块

liuyaqi 3 rokov pred
rodič
commit
b44a9be7ce

+ 4 - 5
config/config.toml

@@ -1,7 +1,7 @@
 # 应用系统设置
 [setting]
 #    logpath = "/tmp/log/admin"
-    bind-addr = "192.168.0.37:18090"
+    bind-addr = "192.168.0.102:18090"
 #    advertise-addr = "81.68.138.114:19922"
     need-advertise-addr = false
     srv-name = "dashoo.lims.adapter-0.1-jlw"
@@ -37,12 +37,11 @@
         link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
     [[database.EmGVD5szuT]]
         Debug = true
-        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_test"
+        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
 
 [micro_srv]
-    auth = "dashoo.labsop.auth-2.1"
-#    admin = "dashoo.labsop.admin-2.1"
-    admin ="dashoo.labsop.admin-2.1,192.168.0.252:19932"
+    auth = "dashoo.labsop.auth-2.1,192.168.0.252:19930"
+    admin = "dashoo.labsop.admin-2.1-pwd,192.168.0.252:19934"
 
 [gfcli]
     [[gfcli.gen.dao]]

+ 100 - 0
handler/learning.go

@@ -0,0 +1,100 @@
+package handler
+
+import (
+	"context"
+	"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 LearningSkill struct{}
+
+func (c *LearningSkill) List(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.List request %v ", &req)
+	s, err := learningSrv.NewLearningSkillService(ctx)
+	if err != nil {
+		return err
+	}
+	ent, err := s.List(ctx)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*learning.LearningSkill{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = ent
+	return nil
+}
+
+func (c *LearningSkill) Get(ctx context.Context, req *learning.LearningSkillGetReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.Get request %v ", &req)
+	s, err := learningSrv.NewLearningSkillService(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 *LearningSkill) Add(ctx context.Context, req *learning.LearningSkillAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	s, err := learningSrv.NewLearningSkillService(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 *LearningSkill) Update(ctx context.Context, req *learning.LearningSkillUpdateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	s, err := learningSrv.NewLearningSkillService(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 *LearningSkill) Delete(ctx context.Context, req *learning.LearningSkillDeleteReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	s, err := learningSrv.NewLearningSkillService(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
+}

+ 25 - 11
main.go

@@ -32,17 +32,31 @@ func main() {
 	s := micro_srv.CreateAndInitService(basePath)
 
 	// 注册服务对象
-	s.RegisterName("Meeting", new(handler.Meeting), "")
-	s.RegisterName("Reservation", new(handler.Reservation), "")
-	s.RegisterName("Equipment", new(handler.Equipment), "")
-	s.RegisterName("System", new(handler.System), "")
-	s.RegisterName("Result", new(handler.Result), "")
-	s.RegisterName("Account", new(handler.Account), "")
-	s.RegisterName("SettleAccountBill", new(handler.SettleAccountBillController), "")
-	s.RegisterName("SettleAccountMain", new(handler.SettleAccountMainController), "")
-	s.RegisterName("SettleAccountDetail", new(handler.SettleAccountDetailController), "")
-	s.RegisterName("InstrumentSurcharge", new(handler.InstrumentSurchargeController), "")
-	s.RegisterName("Test", new((handler.TestController)), "")
+	s.RegisterName("Meeting",
+		new(handler.Meeting), "")
+	s.RegisterName("Reservation",
+		new(handler.Reservation), "")
+	s.RegisterName("Equipment",
+		new(handler.Equipment), "")
+	s.RegisterName("System",
+		new(handler.System), "")
+	s.RegisterName("Result",
+		new(handler.Result), "")
+	s.RegisterName("Account",
+		new(handler.Account), "")
+	s.RegisterName("SettleAccountBill",
+		new(handler.SettleAccountBillController), "")
+	s.RegisterName("SettleAccountMain",
+		new(handler.SettleAccountMainController), "")
+	s.RegisterName("SettleAccountDetail",
+		new(handler.SettleAccountDetailController), "")
+	s.RegisterName("InstrumentSurcharge",
+		new(handler.InstrumentSurchargeController), "")
+	s.RegisterName("Test",
+		new((handler.TestController)), "")
+	s.RegisterName("LearningSkill",
+		new((handler.LearningSkill)), "")
+
 	// 注册auth处理
 	s.AuthFunc = handleAuth
 	// 运行服务

+ 2 - 0
model/base.go

@@ -4,6 +4,8 @@ package model
 	基础字段
 */
 
+type EmptyArgs struct{}
+
 // Page 分页
 type Page struct {
 	Current int `json:"current"`

+ 26 - 0
model/learning/learning_skill.go

@@ -5,6 +5,7 @@
 package learning
 
 import (
+	"lims_adapter/model/equipment"
 	"lims_adapter/model/learning/internal"
 )
 
@@ -12,3 +13,28 @@ import (
 type LearningSkill internal.LearningSkill
 
 // Fill with you ideas below.
+type LearningSkillAddReq struct {
+	Name         string `json:"name" v:"required#请输入技能名称"` // 技能名称
+	InstrumentId []int  `json:"instrumentId"`              // 绑定设备 Id
+}
+
+type LearningSkillGetReq struct {
+	Id   int    `json:"id"`   // Id
+	Name string `json:"name"` // 技能名称
+}
+
+type LearningSkillGetRsp struct {
+	Id         int                    `json:"id"`         // Id
+	Name       string                 `json:"name"`       // 技能名称
+	Instrument []equipment.Instrument `json:"instrument"` // 技能名称
+}
+
+type LearningSkillUpdateReq struct {
+	Id           int    `json:"id" v:"required#请输入技能Id"` // 技能名称
+	Name         string `json:"name"`                    // 技能名称
+	InstrumentId *[]int `json:"instrumentId"`            // 绑定设备 Id
+}
+
+type LearningSkillDeleteReq struct {
+	Id int `json:"id" v:"required#请输入技能Id"` // 技能名称
+}

+ 185 - 0
service/learning/skill.go

@@ -0,0 +1,185 @@
+package learning
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"lims_adapter/dao/learning"
+	"lims_adapter/model/equipment"
+	"lims_adapter/model/learning"
+
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"dashoo.cn/micro_libary/request"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type LearningSkillService struct {
+	LearningSkillDao           *dao.LearningSkillDao
+	LearningSkillInstrumentDao *dao.LearningSkillInstrumentDao
+	Tenant                     string
+	userInfo                   request.UserInfo
+}
+
+func NewLearningSkillService(ctx context.Context) (*LearningSkillService, 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 &LearningSkillService{
+		LearningSkillDao:           dao.NewLearningSkillDao(tenant),
+		LearningSkillInstrumentDao: dao.NewLearningSkillInstrumentDao(tenant),
+		Tenant:                     tenant,
+		userInfo:                   userInfo,
+	}, nil
+}
+
+func (s LearningSkillService) Get(ctx context.Context, req *learning.LearningSkillGetReq) (ent *learning.LearningSkillGetRsp, err error) {
+	var skill *learning.LearningSkill
+	if req.Id != 0 {
+		skill, err = s.LearningSkillDao.Where("Id = ?", req.Id).One()
+		if err != nil {
+			return
+		}
+	}
+	if req.Name != "" {
+		skill, err = s.LearningSkillDao.Where("Name = ?", req.Name).One()
+		if err != nil {
+			return
+		}
+	}
+	if skill == nil {
+		return nil, myerrors.NewMsgError(nil, "技能不存在")
+	}
+
+	instr := []equipment.Instrument{}
+	err = s.LearningSkillDao.DB.
+		Table("learning_skill_instrument a").
+		LeftJoin("instrument b", "a.InstrumentId=b.Id").
+		Where("a.SkillId = ?", skill.Id).
+		Fields("b.*").
+		Structs(&instr)
+	if err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return &learning.LearningSkillGetRsp{
+		Id:         skill.Id,
+		Name:       skill.Name,
+		Instrument: instr,
+	}, nil
+}
+
+func (s LearningSkillService) List(ctx context.Context) ([]*learning.LearningSkill, error) {
+	return s.LearningSkillDao.All()
+}
+
+func (s LearningSkillService) Add(ctx context.Context, req *learning.LearningSkillAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, validErr.Current()
+	}
+
+	skill, err := s.LearningSkillDao.Where("Name = ?", req.Name).One()
+	if err != nil {
+		return 0, err
+	}
+	if skill != nil {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能已存在: %s", req.Name))
+	}
+
+	skillId, err := s.LearningSkillDao.InsertAndGetId(learning.LearningSkill{
+		Name:      req.Name,
+		CreatedAt: gtime.Now(),
+		UpdatedAt: gtime.Now(),
+	})
+	if err != nil {
+		return 0, err
+	}
+
+	relation := []learning.LearningSkillInstrument{}
+	for _, instrumentId := range req.InstrumentId {
+		r, err := g.DB(s.Tenant).Table("instrument").Where("Id = ?", instrumentId).One()
+		if err != nil {
+			return 0, err
+		}
+		if r.IsEmpty() {
+			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("设备不存在: %d", instrumentId))
+		}
+		relation = append(relation, learning.LearningSkillInstrument{
+			SkillId:      int(skillId),
+			InstrumentId: instrumentId,
+		})
+	}
+	_, err = s.LearningSkillInstrumentDao.Insert(relation)
+	return int(skillId), err
+}
+
+func (s LearningSkillService) Update(ctx context.Context, req *learning.LearningSkillUpdateReq) error {
+
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return validErr.Current()
+	}
+
+	if req.Name != "" {
+		skill, err := s.LearningSkillDao.Where("Name = ?", req.Name).One()
+		if err != nil {
+			return err
+		}
+		if skill != nil {
+			return myerrors.NewMsgError(nil, fmt.Sprintf("技能已存在: %s", req.Name))
+		}
+
+		_, err = s.LearningSkillDao.
+			Where("Id = ?", req.Id).
+			Data("Name = ?", req.Name).
+			Update()
+		if err != nil {
+			return err
+		}
+	}
+	if req.InstrumentId != nil {
+		_, err := s.LearningSkillInstrumentDao.
+			Where("SkillId = ?", req.Id).Delete()
+		if err != nil {
+			return err
+		}
+
+		relation := []learning.LearningSkillInstrument{}
+		for _, instrumentId := range *req.InstrumentId {
+			r, err := g.DB(s.Tenant).Table("instrument").Where("Id = ?", instrumentId).One()
+			if err != nil {
+				return err
+			}
+			if r.IsEmpty() {
+				return myerrors.NewMsgError(nil, fmt.Sprintf("设备不存在: %d", instrumentId))
+			}
+			relation = append(relation, learning.LearningSkillInstrument{
+				SkillId:      int(req.Id),
+				InstrumentId: instrumentId,
+			})
+		}
+		_, err = s.LearningSkillInstrumentDao.Insert(relation)
+		return err
+	}
+	return nil
+}
+
+func (s LearningSkillService) Delete(ctx context.Context, id int) error {
+	_, err := s.LearningSkillInstrumentDao.Where("SkillId = ?", id).Delete()
+	if err != nil {
+		return err
+	}
+	_, err = s.LearningSkillDao.Where("Id = ?", id).Delete()
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 186 - 1
swaggerui/swagger.yml

@@ -7,6 +7,8 @@ info:
 paths:
     /Test.Nullable:
       post:
+        tags:
+          - 测试
         operationId: Test.Nullable
         summary: 测试空值参数
         requestBody:
@@ -28,6 +30,131 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningSkill.List:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkill.List
+        summary: 技能列表
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/NoArgs'
+              examples:
+                NoArgs:
+                  $ref: '#/components/examples/NoArgs'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningSkill.Get:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkill.Get
+        summary: 技能详情
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningSkillGet'
+              examples:
+                LearningSkillGet:
+                  $ref: '#/components/examples/LearningSkillGet'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningSkill.Add:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkill.Add
+        summary: 添加技能
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningSkillAdd'
+              examples:
+                LearningSkillAdd:
+                  $ref: '#/components/examples/LearningSkillAdd'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningSkill.Update:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkill.Update
+        summary: 更新技能
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningSkillUpdate'
+              examples:
+                LearningSkillUpdate:
+                  $ref: '#/components/examples/LearningSkillUpdate'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningSkill.Delete:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkill.Delete
+        summary: 删除技能
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/IdReq'
+              examples:
+                LearningSkillDelete:
+                  $ref: '#/components/examples/LearningSkillDelete'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
 # 添加这个 swagger ui 会显示授权按钮
 security:
   - bearerAuth: []
@@ -63,6 +190,47 @@ components:
           description: Slice 参数
           items:
             type: integer
+    NoArgs:
+      type: object
+      properties:
+        noargs:
+          type: string
+          description: 无参数,但是 body 中必须传输一个 json 空对象 "{}"
+    LearningSkillGet:
+      properties:
+        id:
+          type: string
+          description: 技能 id
+        name:
+          type: string
+          description: 技能名称
+    LearningSkillAdd:
+      properties:
+        instrumentId:
+          type: string
+          description: 技能关联的设备 id
+        name:
+          type: string
+          description: 技能名称
+    LearningSkillUpdate:
+      properties:
+        id:
+          type: string
+          description: 技能 id
+        instrumentId:
+          type: string
+          description: 技能关联的设备 id
+        name:
+          type: string
+          description: 技能名称
+    IdReq:
+      type: object
+      required:
+        - id
+      properties:
+        id:
+          type: integer
+          description: ID
 
   examples:
     success:
@@ -70,10 +238,27 @@ components:
       value:
         code: 200,
         msg: "success"
-
     NullableReqAllPass:
       value:
           Str: ""
           Int: 0
           Bool: false
           Slice: []
+    NoArgs:
+      value:
+        noargs: ""
+    LearningSkillGet:
+      value:
+        Id: 1
+    LearningSkillAdd:
+      value:
+        name: 测试
+        instrumentId: [1,2]
+    LearningSkillUpdate:
+      value:
+        name: 测试更新
+        instrumentId: [3,4]
+        id: 1
+    LearningSkillDelete:
+      value:
+        id: 1