Răsfoiți Sursa

feature:添培训考试的资料管理

liuyaqi 3 ani în urmă
părinte
comite
90f71dfa0f

+ 3 - 3
dao/learning/internal/learning_material.go

@@ -33,7 +33,7 @@ type learningMaterialColumns struct {
 	SortNo    string // 排序
 	Enable    string // 是否启用
 	Content   string // 资料内容
-	Annex     string // 附件路径
+	OperateBy string // 操作人
 	CreatedAt string // 创建时间
 	UpdatedAt string // 更新时间
 	DeletedAt string // 删除时间
@@ -53,7 +53,7 @@ var (
 			SortNo:    "SortNo",
 			Enable:    "Enable",
 			Content:   "Content",
-			Annex:     "Annex",
+			OperateBy: "OperateBy",
 			CreatedAt: "CreatedAt",
 			UpdatedAt: "UpdatedAt",
 			DeletedAt: "DeletedAt",
@@ -75,7 +75,7 @@ func NewLearningMaterialDao(tenant string) LearningMaterialDao {
 			SortNo:    "SortNo",
 			Enable:    "Enable",
 			Content:   "Content",
-			Annex:     "Annex",
+			OperateBy: "OperateBy",
 			CreatedAt: "CreatedAt",
 			UpdatedAt: "UpdatedAt",
 			DeletedAt: "DeletedAt",

+ 423 - 0
dao/learning/internal/learning_material_file.go

@@ -0,0 +1,423 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"time"
+
+	model "lims_adapter/model/learning"
+)
+
+// LearningMaterialFileDao is the manager for logic model data accessing
+// and custom defined data operations functions management.
+type LearningMaterialFileDao struct {
+	gmvc.M
+	DB      gdb.DB
+	Table   string
+	Columns learningMaterialFileColumns
+}
+
+// LearningMaterialFileColumns defines and stores column names for table learning_material_file.
+type learningMaterialFileColumns struct {
+	Id         string // Id
+	MaterialId string // 资料 Id
+	Name       string // 文件名
+	Url        string // 文件地址
+	Size       string // 文件大小
+	Extend     string // 文件扩展名
+	OperateBy  string // 操作人
+	CreatedAt  string // 创建时间
+	UpdatedAt  string // 更新时间
+	DeletedAt  string // 删除时间
+}
+
+var (
+	// LearningMaterialFile is globally public accessible object for table learning_material_file operations.
+	LearningMaterialFile = LearningMaterialFileDao{
+		M:     g.DB("default").Model("learning_material_file").Safe(),
+		DB:    g.DB("default"),
+		Table: "learning_material_file",
+		Columns: learningMaterialFileColumns{
+			Id:         "Id",
+			MaterialId: "MaterialId",
+			Name:       "Name",
+			Url:        "Url",
+			Size:       "Size",
+			Extend:     "Extend",
+			OperateBy:  "OperateBy",
+			CreatedAt:  "CreatedAt",
+			UpdatedAt:  "UpdatedAt",
+			DeletedAt:  "DeletedAt",
+		},
+	}
+)
+
+func NewLearningMaterialFileDao(tenant string) LearningMaterialFileDao {
+	var dao LearningMaterialFileDao
+	dao = LearningMaterialFileDao{
+		M:     g.DB(tenant).Model("learning_material_file").Safe(),
+		DB:    g.DB(tenant),
+		Table: "learning_material_file",
+		Columns: learningMaterialFileColumns{
+			Id:         "Id",
+			MaterialId: "MaterialId",
+			Name:       "Name",
+			Url:        "Url",
+			Size:       "Size",
+			Extend:     "Extend",
+			OperateBy:  "OperateBy",
+			CreatedAt:  "CreatedAt",
+			UpdatedAt:  "UpdatedAt",
+			DeletedAt:  "DeletedAt",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *LearningMaterialFileDao) Ctx(ctx context.Context) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Ctx(ctx)}
+}
+
+// As sets an alias name for current table.
+func (d *LearningMaterialFileDao) As(as string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (d *LearningMaterialFileDao) TX(tx *gdb.TX) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (d *LearningMaterialFileDao) Master() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *LearningMaterialFileDao) Slave() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Slave()}
+}
+
+// Args sets custom arguments for model operation.
+func (d *LearningMaterialFileDao) Args(args ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Args(args...)}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *LearningMaterialFileDao) LeftJoin(table ...string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.LeftJoin(table...)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *LearningMaterialFileDao) RightJoin(table ...string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.RightJoin(table...)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *LearningMaterialFileDao) InnerJoin(table ...string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.InnerJoin(table...)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *LearningMaterialFileDao) Fields(fieldNamesOrMapStruct ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *LearningMaterialFileDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
+}
+
+// Option sets the extra operation option for the model.
+func (d *LearningMaterialFileDao) Option(option int) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *LearningMaterialFileDao) OmitEmpty() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (d *LearningMaterialFileDao) Filter() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *LearningMaterialFileDao) Where(where interface{}, args ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Where(where, args...)}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *LearningMaterialFileDao) WherePri(where interface{}, args ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.WherePri(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (d *LearningMaterialFileDao) And(where interface{}, args ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (d *LearningMaterialFileDao) Or(where interface{}, args ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *LearningMaterialFileDao) Group(groupBy string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *LearningMaterialFileDao) Order(orderBy ...string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Order(orderBy...)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *LearningMaterialFileDao) Limit(limit ...int) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *LearningMaterialFileDao) Offset(offset int) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *LearningMaterialFileDao) Page(page, limit int) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *LearningMaterialFileDao) Batch(batch int) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *LearningMaterialFileDao) Cache(duration time.Duration, name ...string) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Cache(duration, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *LearningMaterialFileDao) Data(data ...interface{}) *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Data(data...)}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.LearningMaterialFile.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *LearningMaterialFileDao) All(where ...interface{}) ([]*model.LearningMaterialFile, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.LearningMaterialFile
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.LearningMaterialFile.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *LearningMaterialFileDao) One(where ...interface{}) (*model.LearningMaterialFile, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.LearningMaterialFile
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *LearningMaterialFileDao) FindOne(where ...interface{}) (*model.LearningMaterialFile, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.LearningMaterialFile
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *LearningMaterialFileDao) FindAll(where ...interface{}) ([]*model.LearningMaterialFile, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.LearningMaterialFile
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *LearningMaterialFileDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *LearningMaterialFileDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *LearningMaterialFileDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *LearningMaterialFileDao) Chunk(limit int, callback func(entities []*model.LearningMaterialFile, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.LearningMaterialFile
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *LearningMaterialFileDao) LockUpdate() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *LearningMaterialFileDao) LockShared() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *LearningMaterialFileDao) Unscoped() *LearningMaterialFileDao {
+	return &LearningMaterialFileDao{M: d.M.Unscoped()}
+}

+ 36 - 0
dao/learning/learning_material_file.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package dao
+
+import (
+	"lims_adapter/dao/learning/internal"
+)
+
+// learningMaterialFileDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type learningMaterialFileDao struct {
+	internal.LearningMaterialFileDao
+}
+
+var (
+	// LearningMaterialFile is globally public accessible object for table learning_material_file operations.
+	LearningMaterialFile = learningMaterialFileDao{
+		internal.LearningMaterialFile,
+	}
+)
+
+type LearningMaterialFileDao struct {
+	internal.LearningMaterialFileDao
+}
+
+func NewLearningMaterialFileDao(tenant string) *LearningMaterialFileDao {
+	dao := internal.NewLearningMaterialFileDao(tenant)
+	return &LearningMaterialFileDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 102 - 0
handler/learning/material.go

@@ -0,0 +1,102 @@
+package learning
+
+import (
+	"context"
+	"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 LearningMaterial struct{}
+
+func (c *LearningMaterial) List(ctx context.Context, req *learning.LearningMaterialListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.List request %v ", &req)
+	s, err := learningSrv.NewLearningMaterialService(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.LearningMaterial{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+func (c *LearningMaterial) Get(ctx context.Context, req *learning.LearningMaterialGetReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.Get request %v ", &req)
+	s, err := learningSrv.NewLearningMaterialService(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 *LearningMaterial) Add(ctx context.Context, req *learning.LearningMaterialAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	s, err := learningSrv.NewLearningMaterialService(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 *LearningMaterial) Update(ctx context.Context, req *learning.LearningMaterialUpdateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	s, err := learningSrv.NewLearningMaterialService(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 *LearningMaterial) Delete(ctx context.Context, req *learning.LearningMaterialDeleteReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	s, err := learningSrv.NewLearningMaterialService(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
+}

+ 2 - 0
main.go

@@ -58,6 +58,8 @@ func main() {
 		new((handler.TestController)), "")
 	s.RegisterName("LearningSkill",
 		new((learning.LearningSkill)), "")
+	s.RegisterName("LearningMaterial",
+		new((learning.LearningMaterial)), "")
 
 	// 注册auth处理
 	s.AuthFunc = handleAuth

+ 1 - 1
model/learning/internal/learning_material.go

@@ -17,7 +17,7 @@ type LearningMaterial struct {
 	SortNo    int         `orm:"SortNo"     json:"sortNo"`    // 排序
 	Enable    int         `orm:"Enable"     json:"enable"`    // 是否启用
 	Content   string      `orm:"Content"    json:"content"`   // 资料内容
-	Annex     string      `orm:"Annex"      json:"annex"`     // 附件路径
+	OperateBy string      `orm:"OperateBy"  json:"operateBy"` // 操作人
 	CreatedAt *gtime.Time `orm:"CreatedAt"  json:"createdAt"` // 创建时间
 	UpdatedAt *gtime.Time `orm:"UpdatedAt"  json:"updatedAt"` // 更新时间
 	DeletedAt *gtime.Time `orm:"DeletedAt"  json:"deletedAt"` // 删除时间

+ 23 - 0
model/learning/internal/learning_material_file.go

@@ -0,0 +1,23 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// LearningMaterialFile is the golang structure for table learning_material_file.
+type LearningMaterialFile struct {
+	Id         int         `orm:"Id,primary" json:"id"`         // Id
+	MaterialId int         `orm:"MaterialId" json:"materialId"` // 资料 Id
+	Name       string      `orm:"Name"       json:"name"`       // 文件名
+	Url        string      `orm:"Url"        json:"url"`        // 文件地址
+	Size       string      `orm:"Size"       json:"size"`       // 文件大小
+	Extend     string      `orm:"Extend"     json:"extend"`     // 文件扩展名
+	OperateBy  string      `orm:"OperateBy"  json:"operateBy"`  // 操作人
+	CreatedAt  *gtime.Time `orm:"CreatedAt"  json:"createdAt"`  // 创建时间
+	UpdatedAt  *gtime.Time `orm:"UpdatedAt"  json:"updatedAt"`  // 更新时间
+	DeletedAt  *gtime.Time `orm:"DeletedAt"  json:"deletedAt"`  // 删除时间
+}

+ 49 - 0
model/learning/learning_material.go

@@ -5,6 +5,7 @@
 package learning
 
 import (
+	"lims_adapter/model"
 	"lims_adapter/model/learning/internal"
 )
 
@@ -12,3 +13,51 @@ import (
 type LearningMaterial internal.LearningMaterial
 
 // Fill with you ideas below.
+type LearningMaterialListReq struct {
+	Page    *model.Page    `json:"page"`
+	OrderBy *model.OrderBy `json:"orderBy"`
+	SkillId int            `json:"skillId"`
+	Name    string         `json:"name"`
+}
+
+type LearningMaterialGetReq struct {
+	Id   int    `json:"id"`   // 资料Id
+	Name string `json:"name"` // 资料名称
+}
+
+type LearningMaterialGetRsp struct {
+	LearningMaterial
+	File []*LearningMaterialFile `json:"file"`
+}
+
+type LearningMaterialAddReqFile struct {
+	Name   string `json:"name"`   // 文件名
+	Url    string `json:"url"`    // 文件地址
+	Size   string `json:"size"`   // 文件大小
+	Extend string `json:"extend"` // 文件扩展名
+}
+
+type LearningMaterialAddReq struct {
+	SkillId int                           `json:"skillId" v:"required#请输入技能Id"`                // 技能 Id
+	Name    string                        `json:"name" v:"required#请输入资料名称"`                   // 资料名称
+	Type    int                           `json:"type" v:"required#请输入资料类型 in:1,2#请输入正确的资料类型"` // 资料类型 1 资料 2 视频
+	SortNo  int                           `json:"sortNo"`                                      // 排序
+	Enable  int                           `json:"enable" v:"in:0,1#请输入正确的启用类型"`                // 是否启用
+	Content string                        `json:"content"`                                     // 资料内容
+	File    []*LearningMaterialAddReqFile `json:"file"`                                        // 附件
+}
+
+type LearningMaterialUpdateReq struct {
+	Id      int                           `json:"id" v:"required#请输入资料Id"`      // Id
+	SkillId int                           `json:"skillId"`                      // 技能 Id
+	Name    string                        `json:"name"`                         // 资料名称
+	Type    int                           `json:"type" v:"in:1,2#请输入正确的资料类型"`   // 资料类型 1 资料 2 视频
+	SortNo  *int                          `json:"sortNo"`                       // 排序
+	Enable  *int                          `json:"enable" v:"in:0,1#请输入正确的启用类型"` // 是否启用
+	Content string                        `json:"content"`                      // 资料内容
+	File    []*LearningMaterialAddReqFile `json:"file"`                         // 附件
+}
+
+type LearningMaterialDeleteReq struct {
+	Id int `json:"id" v:"required#请输入资料Id"`
+}

+ 14 - 0
model/learning/learning_material_file.go

@@ -0,0 +1,14 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package learning
+
+import (
+	"lims_adapter/model/learning/internal"
+)
+
+// LearningMaterialFile is the golang structure for table learning_material_file.
+type LearningMaterialFile internal.LearningMaterialFile
+
+// Fill with you ideas below.

+ 243 - 0
service/learning/material.go

@@ -0,0 +1,243 @@
+package learning
+
+import (
+	"context"
+	"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 LearningMaterialService struct {
+	Dao      *dao.LearningMaterialDao
+	FileDao  *dao.LearningMaterialFileDao
+	Tenant   string
+	userInfo request.UserInfo
+}
+
+func NewLearningMaterialService(ctx context.Context) (*LearningMaterialService, 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 &LearningMaterialService{
+		Dao:      dao.NewLearningMaterialDao(tenant),
+		FileDao:  dao.NewLearningMaterialFileDao(tenant),
+		Tenant:   tenant,
+		userInfo: userInfo,
+	}, nil
+}
+
+func (s LearningMaterialService) Get(ctx context.Context, req *learning.LearningMaterialGetReq) (ent *learning.LearningMaterialGetRsp, err error) {
+	var m *learning.LearningMaterial
+	if req.Id != 0 {
+		m, err = s.Dao.Where("Id = ?", req.Id).One()
+		if err != nil {
+			return
+		}
+	}
+	if req.Name != "" {
+		m, err = s.Dao.Where("Name = ?", req.Name).One()
+		if err != nil {
+			return
+		}
+	}
+	if m == nil {
+		return nil, myerrors.NewMsgError(nil, "培训材料不存在")
+	}
+	file, err := s.FileDao.Where("MaterialId = ?", m.Id).All()
+	if err != nil {
+		return nil, err
+	}
+
+	return &learning.LearningMaterialGetRsp{
+		LearningMaterial: *m,
+		File:             file,
+	}, nil
+}
+
+func (s LearningMaterialService) List(ctx context.Context, req *learning.LearningMaterialListReq) (int, []*learning.LearningMaterial, error) {
+	dao := &s.Dao.LearningMaterialDao
+	if req.Name != "" {
+		dao = dao.Where("Name LIKE ?", fmt.Sprintf("%%%s%%", req.Name))
+	}
+	if req.SkillId != 0 {
+		dao = dao.Where("SkillId = ?", req.SkillId)
+	}
+	total, err := dao.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
+		}
+		dao = dao.Page(req.Page.Current, req.Page.Size)
+	}
+
+	if req.OrderBy != nil && req.OrderBy.Value != "" {
+		order := "asc"
+		if req.OrderBy.Type == "desc" {
+			order = "desc"
+		}
+		dao = dao.Order(req.OrderBy.Value, order)
+	}
+	ent, err := dao.All()
+	return total, ent, err
+}
+
+func (s LearningMaterialService) Add(ctx context.Context, req *learning.LearningMaterialAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, validErr.Current()
+	}
+
+	m, err := s.Dao.Where("Name = ?", req.Name).One()
+	if err != nil {
+		return 0, err
+	}
+	if m != nil {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("资料已存在: %s", req.Name))
+	}
+
+	id, err := s.Dao.InsertAndGetId(learning.LearningMaterial{
+		SkillId:   req.SkillId,
+		Name:      req.Name,
+		Type:      req.Type,
+		SortNo:    req.SortNo,
+		Enable:    req.Enable,
+		Content:   req.Content,
+		OperateBy: s.userInfo.RealName,
+		CreatedAt: gtime.Now(),
+		UpdatedAt: gtime.Now(),
+	})
+	if err != nil {
+		return 0, err
+	}
+
+	files := []learning.LearningMaterialFile{}
+	for _, f := range req.File {
+		files = append(files, learning.LearningMaterialFile{
+			MaterialId: int(id),
+			Name:       f.Name,
+			Url:        f.Url,
+			Size:       f.Size,
+			Extend:     f.Extend,
+			OperateBy:  s.userInfo.RealName,
+			CreatedAt:  gtime.Now(),
+			UpdatedAt:  gtime.Now(),
+		})
+	}
+	_, err = s.FileDao.Insert(files)
+	return int(id), err
+}
+
+func (s LearningMaterialService) Update(ctx context.Context, req *learning.LearningMaterialUpdateReq) error {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return validErr.Current()
+	}
+
+	m, err := s.Dao.Where("Id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if m == nil {
+		return myerrors.NewMsgError(nil, fmt.Sprintf("资料不存在: %d", req.Id))
+	}
+
+	if req.SkillId != 0 {
+		r, err := s.Dao.DB.Table("learning_skill").Where("Id", req.SkillId).One()
+		if err != nil {
+			return err
+		}
+		if r.IsEmpty() {
+			return myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
+		}
+	}
+
+	if req.Name != "" {
+		existM, err := s.Dao.Where("Name = ?", req.Name).One()
+		if err != nil {
+			return err
+		}
+		if existM != nil && existM.Id != m.Id {
+			return myerrors.NewMsgError(nil, fmt.Sprintf("资料已存在: %s", req.Name))
+		}
+	}
+
+	dao := &s.Dao.LearningMaterialDao
+	toupdate := map[string]interface{}{}
+	if req.SkillId != 0 {
+		toupdate["SkillId"] = req.SkillId
+	}
+	if req.Name != "" {
+		toupdate["Name"] = req.Name
+	}
+	if req.Type != 0 {
+		toupdate["Type"] = req.Type
+	}
+	if req.SortNo != nil {
+		toupdate["SortNo"] = req.SortNo
+	}
+	if req.Enable != nil {
+		toupdate["Enable"] = req.Enable
+	}
+	if req.Content != "" {
+		toupdate["Content"] = req.Content
+	}
+	if len(toupdate) == 0 {
+		return nil
+	}
+	toupdate["OperateBy"] = s.userInfo.RealName
+	_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
+	if err != nil {
+		return err
+	}
+	if req.File == nil {
+		return nil
+	}
+
+	_, err = s.FileDao.Where("MaterialId = ?", req.Id).Delete()
+	if err != nil {
+		return err
+	}
+	files := []learning.LearningMaterialFile{}
+	for _, f := range req.File {
+		files = append(files, learning.LearningMaterialFile{
+			MaterialId: m.Id,
+			Name:       f.Name,
+			Url:        f.Url,
+			Size:       f.Size,
+			Extend:     f.Extend,
+			OperateBy:  s.userInfo.RealName,
+			CreatedAt:  gtime.Now(),
+			UpdatedAt:  gtime.Now(),
+		})
+	}
+	_, err = s.FileDao.Insert(files)
+	return err
+}
+
+func (s LearningMaterialService) Delete(ctx context.Context, id int) error {
+	_, err := s.Dao.Where("Id = ?", id).Delete()
+	if err != nil {
+		return err
+	}
+	_, err = s.FileDao.Where("MaterialId = ?", id).Delete()
+	return err
+}

+ 16 - 1
sql/create.sql

@@ -42,7 +42,7 @@ CREATE TABLE `learning_material` (
   `SortNo` int NOT NULL COMMENT '排序',
   `Enable` tinyint(1) NOT NULL COMMENT '是否启用',
   `Content` text COMMENT '资料内容',
-  `Annex` text COMMENT '附件路径',
+  `OperateBy` varchar(255) COMMENT '操作人',
   `CreatedAt` datetime COMMENT '创建时间',
   `UpdatedAt` datetime COMMENT '更新时间',
   `DeletedAt` datetime COMMENT '删除时间',
@@ -50,6 +50,21 @@ CREATE TABLE `learning_material` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='资料表';
 
 
+CREATE TABLE `learning_material_file` (
+  `Id` int NOT NULL AUTO_INCREMENT COMMENT 'Id',
+  `MaterialId` int NOT NULL COMMENT '资料 Id',
+  `Name` varchar(255) NOT NULL COMMENT '文件名',
+  `Url` varchar(255) NOT NULL COMMENT '文件地址',
+  `Size` varchar(255) NOT NULL COMMENT '文件大小',
+  `Extend` varchar(255) NOT NULL COMMENT '文件扩展名',
+  `OperateBy` varchar(255) COMMENT '操作人',
+  `CreatedAt` datetime COMMENT '创建时间',
+  `UpdatedAt` datetime COMMENT '更新时间',
+  `DeletedAt` datetime COMMENT '删除时间',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='资料文件表';
+
+
 CREATE TABLE `learning_question` (
   `Id` int NOT NULL AUTO_INCREMENT COMMENT 'Id',
   `SkillId` int NOT NULL COMMENT '技能 Id',

+ 312 - 0
swaggerui/swagger.yml

@@ -155,6 +155,131 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningMaterial.List:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterial.List
+        summary: 查询资料
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningMaterialList'
+              examples:
+                LearningMaterialList:
+                  $ref: '#/components/examples/LearningMaterialList'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningMaterial.Get:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterialGet
+        summary: 资料详情
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningMaterialGet'
+              examples:
+                LearningMaterialGet:
+                  $ref: '#/components/examples/LearningMaterialGet'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningMaterial.Add:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterialAdd
+        summary: 添加资料
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningMaterialAdd'
+              examples:
+                LearningMaterialAdd:
+                  $ref: '#/components/examples/LearningMaterialAdd'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningMaterial.Update:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterialUpdate
+        summary: 修改资料
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningMaterialUpdate'
+              examples:
+                LearningMaterialUpdate:
+                  $ref: '#/components/examples/LearningMaterialUpdate'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningMaterial.Delete:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterialDelete
+        summary: 删除资料
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/IdReq'
+              examples:
+                LearningMaterialDelete:
+                  $ref: '#/components/examples/LearningMaterialDelete'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
 # 添加这个 swagger ui 会显示授权按钮
 security:
   - bearerAuth: []
@@ -213,6 +338,8 @@ components:
           type: string
           description: 技能名称
     LearningSkillUpdate:
+      required:
+        - id
       properties:
         id:
           type: string
@@ -231,6 +358,136 @@ components:
         id:
           type: integer
           description: ID
+    LearningMaterialList:
+      type: object
+      required:
+        - id
+      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: 按技能 Id 查询
+        name:
+          type: string
+          description: 按资料名称模糊查询
+    LearningMaterialGet:
+      type: object
+      properties:
+        id:
+          type: string
+          description: 资料 id
+        name:
+          type: string
+          description: 资料名称
+    LearningMaterialAdd:
+      type: object
+      required:
+        - skillId
+        - name
+        - type
+      properties:
+          skillId:
+            type: integer
+            description: 技能 Id
+          name:
+            type: string
+            description: 资料名称
+          type:
+            type: integer
+            description: 资料类型 1 资料 2 视频
+          sortNo:
+            type: integer
+            description: 排序
+          enable:
+            type: integer
+            description: 是否启用 0 未启用 1 启用
+          content:
+            type: string
+            description: 资料内容
+          file:
+            type: array
+            description: 附件
+            items:
+              type: object
+              properties:
+                name:
+                  type: string
+                  description: 文件名
+                url:
+                  type: string
+                  description: 文件地址
+                size:
+                  type: string
+                  description: 文件大小
+                extend:
+                  type: string
+                  description: 文件扩展名
+    LearningMaterialUpdate:
+      type: object
+      required:
+        - id
+      properties:
+          id:
+            type: integer
+            description: 资料 id
+          skillId:
+            type: integer
+            description: 技能 Id
+          name:
+            type: string
+            description: 资料名称
+          type:
+            type: integer
+            description: 资料类型 1 资料 2 视频
+          sortNo:
+            type: integer
+            description: 排序
+          enable:
+            type: integer
+            description: 是否启用 0 未启用 1 启用
+          content:
+            type: string
+            description: 资料内容
+          file:
+            type: array
+            description: 附件
+            items:
+              type: object
+              properties:
+                name:
+                  type: string
+                  description: 文件名
+                url:
+                  type: string
+                  description: 文件地址
+                size:
+                  type: string
+                  description: 文件大小
+                extend:
+                  type: string
+                  description: 文件扩展名
 
   examples:
     success:
@@ -262,3 +519,58 @@ components:
     LearningSkillDelete:
       value:
         id: 1
+    LearningMaterialList:
+      value:
+        page:
+          current: 2
+          size: 2
+        orderBy:
+          type: desc
+          value: id
+        skillId: 2
+        name: "测试"
+    LearningMaterialGet:
+      value:
+        id: 1
+    LearningMaterialAdd:
+      value:
+        skillId: 2
+        name: 测试 1
+        type: 2
+        sortNo:
+        enable: 1
+        content: 测试
+        file:
+          -
+            name: "1"
+            url: 1.txt
+            size: "1"
+            extend: .txt
+          -
+            name: "2"
+            url: 2.txt
+            size: "2"
+            extend: .txt
+    LearningMaterialUpdate:
+      value:
+        id: 1
+        skillId: 4
+        name: 测试修改
+        type: 1
+        sortNo: 5
+        enable: 0
+        content: 测试修改
+        file:
+          -
+            name: "3"
+            url: 3.txt
+            size: "3"
+            extend: .txt
+          -
+            name: "4"
+            url: 4.txt
+            size: "4"
+            extend: .txt
+    LearningMaterialDelete:
+      value:
+        id: 1