biz

package
v0.0.0-...-361a7e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 9 Imported by: 0

README

Biz层的简单介绍

biz.go

这个文件主要是提供wire依赖注入的ProviderSet,以及定义了Transaction的接口(其主要是为了优雅地调用gorm中的事务)

classer.go

1、定义了爬虫的接口,由pkg/crawler/crawler.go中的Crawler来实现去CCNU教务管理系统中爬取课表 2、定义了ClassUsercase ,并实现了关于课程的相关方法,以便service来调用

classInfo.go

1、定义了ClassInfoDBRepoClassInfoCacheRepo的接口,由data层中ClassInfoRepo.go中的相关实例实现,分别控制在mysql和redis中对ClassInfo的操作 2、定义了ClassInfoRepo,集成了ClassInfoDBRepoClassInfoCacheRepo,使其能够直接控制ClassInfo的所有操作

studentAndCourse.go

1、定义了StudentAndCourseDBRepoStudentAndCourseCacheRepo接口,由data层中StudentAndCourse.go中的相关实例实现,分别控制在mysql和redis中对StudentCourse的操作 2、定义了StudentAndCourseRepo,集成了StudentAndCourseDBRepoStudentAndCourseCacheRepo,使其能够直接控制StudentCourse的所有操作

classRepo.go

便于同时操作ClassInfoStudentCourse

model.go

1、定义ClassInfo,其表示课程信息, 2、定义StudentCourse,其表示学生与课程之间的对应关系

Documentation

Index

Constants

View Source
const (
	ClassInfoTableName     string = "class_info"
	StudentCourseTableName string = "student_course"
)

Variables

ProviderSet is biz providers.

Functions

func GenerateClassInfoKey

func GenerateClassInfoKey(classId string) string

func GenerateClassInfosKey

func GenerateClassInfosKey(stuId, xnm, xqm string) string

func GenerateRecycleSetName

func GenerateRecycleSetName(stuId, xnm, xqm string) string

func GenerateSCID

func GenerateSCID(stuId, classId, xnm, xqm string) string

func GenerateScSetName

func GenerateScSetName(stuId, xnm, xqm string) string

Types

type Class

type Class struct {
	Info     *ClassInfo //课程信息
	ThisWeek bool       //是否是本周
}

type ClassCrawler

type ClassCrawler interface {
	GetClassInfosForUndergraduate(ctx context.Context, cookie string, xnm, xqm string) ([]*ClassInfo, []*StudentCourse, error)
	GetClassInfoForGraduateStudent(ctx context.Context, cookie string, xnm, xqm string) ([]*ClassInfo, []*StudentCourse, error)
}

ClassCrawler 课程爬虫接口

type ClassInfo

type ClassInfo struct {
	ID        string `gorm:"primaryKey;column:id" json:"id"` //集合了课程信息的字符串,便于标识(课程ID)
	CreatedAt time.Time
	UpdatedAt time.Time
	//ClassId      string  `gorm:"column:class_id" json:"class_id"`           //课程编号
	Day          int64   `gorm:"column:day;not null" json:"day"`                     //星期几
	Teacher      string  `gorm:"column:teacher;not null" json:"teacher"`             //任课教师
	Where        string  `gorm:"column:where;not null" json:"where"`                 //上课地点
	ClassWhen    string  `gorm:"column:class_when;not null" json:"class_when"`       //上课是第几节(如1-2,3-4)
	WeekDuration string  `gorm:"column:week_duration;not null" json:"week_duration"` //上课的周数
	Classname    string  `gorm:"column:class_name;not null" json:"classname"`        //课程名称
	Credit       float64 `gorm:"column:credit;default:1.0" json:"credit"`            //学分
	Weeks        int64   `gorm:"column:weeks;not null" json:"weeks"`                 //哪些周
	Semester     string  `gorm:"column:semester;not null;index" json:"semester"`     //学期
	Year         string  `gorm:"column:year;not null;index" json:"year"`             //学年
}

func (*ClassInfo) AddWeek

func (ci *ClassInfo) AddWeek(week int64)

func (*ClassInfo) BeforeCreate

func (ci *ClassInfo) BeforeCreate(tx *gorm.DB) (err error)

func (*ClassInfo) BeforeUpdate

func (ci *ClassInfo) BeforeUpdate(tx *gorm.DB) (err error)

func (*ClassInfo) SearchWeek

func (ci *ClassInfo) SearchWeek(week int64) bool

func (*ClassInfo) TableName

func (ci *ClassInfo) TableName() string

func (*ClassInfo) UpdateID

func (ci *ClassInfo) UpdateID()

type ClassInfoCacheRepo

type ClassInfoCacheRepo interface {
	SaveManyClassInfosToCache(ctx context.Context, keys []string, classInfos []*ClassInfo) error
	OnlyAddClassInfoToCache(ctx context.Context, key string, classInfo *ClassInfo) error
	OnlyAddClassInfosToCache(ctx context.Context, key string, classInfos []*ClassInfo) error
	AddClassInfoToCache(ctx context.Context, classInfoKey, classInfosKey string, classInfo *ClassInfo) error
	GetClassInfoFromCache(ctx context.Context, key string) (*ClassInfo, error)
	GetClassInfosFromCache(ctx context.Context, key string) ([]*ClassInfo, error)
	DeleteClassInfoFromCache(ctx context.Context, deletedId, classInfosKey string) error
	FixClassInfoInCache(ctx context.Context, oldID, classInfoKey, classInfosKey string, classInfo *ClassInfo) error
}

type ClassInfoDBRepo

type ClassInfoDBRepo interface {
	SaveClassInfosToDB(ctx context.Context, classInfo []*ClassInfo) error
	AddClassInfoToDB(ctx context.Context, classInfo *ClassInfo) error
	GetClassInfoFromDB(ctx context.Context, ID string) (*ClassInfo, error)
	DeleteClassInfoInDB(ctx context.Context, ID string) error
	GetAllClassInfos(ctx context.Context, xnm, xqm string) ([]*ClassInfo, error)
}

type ClassInfoRepo

type ClassInfoRepo struct {
	DB    ClassInfoDBRepo
	Cache ClassInfoCacheRepo
}

func NewClassInfoRepo

func NewClassInfoRepo(DB ClassInfoDBRepo, Cache ClassInfoCacheRepo) *ClassInfoRepo

type ClassRepo

type ClassRepo struct {
	ClaRepo *ClassInfoRepo
	Sac     *StudentAndCourseRepo
	TxCtrl  Transaction //控制事务的开启
	// contains filtered or unexported fields
}

func NewClassRepo

func NewClassRepo(ClaRepo *ClassInfoRepo, TxCtrl Transaction, Sac *StudentAndCourseRepo, log log.LogerPrinter) *ClassRepo

func (ClassRepo) AddClass

func (cla ClassRepo) AddClass(ctx context.Context, classInfo *ClassInfo, sc *StudentCourse, xnm, xqm string) error

func (ClassRepo) CheckClassIdIsInRecycledBin

func (cla ClassRepo) CheckClassIdIsInRecycledBin(ctx context.Context, stuId, xnm, xqm, classId string) bool

func (ClassRepo) CheckSCIdsExist

func (cla ClassRepo) CheckSCIdsExist(ctx context.Context, stuId, classId, xnm, xqm string) bool

func (ClassRepo) DeleteClass

func (cla ClassRepo) DeleteClass(ctx context.Context, classId string, stuId string, xnm string, xqm string) error

func (ClassRepo) GetAllClasses

func (cla ClassRepo) GetAllClasses(ctx context.Context, stuId, xnm, xqm string) ([]*ClassInfo, error)

func (ClassRepo) GetAllSchoolClassInfos

func (cla ClassRepo) GetAllSchoolClassInfos(ctx context.Context, xnm, xqm string) []*ClassInfo

func (ClassRepo) GetRecycledIds

func (cla ClassRepo) GetRecycledIds(ctx context.Context, stuId, xnm, xqm string) ([]string, error)

func (ClassRepo) GetSpecificClassInfo

func (cla ClassRepo) GetSpecificClassInfo(ctx context.Context, classId string) (*ClassInfo, error)

func (ClassRepo) RemoveClassFromRecycledBin

func (cla ClassRepo) RemoveClassFromRecycledBin(ctx context.Context, stuId, xnm, xqm, classId string) error

func (ClassRepo) SaveClasses

func (cla ClassRepo) SaveClasses(ctx context.Context, stuId, xnm, xqm string, claInfos []*ClassInfo, scs []*StudentCourse) error

func (ClassRepo) UpdateClass

func (cla ClassRepo) UpdateClass(ctx context.Context, newClassInfo *ClassInfo, newSc *StudentCourse, stuId, oldClassId, xnm, xqm string) error

type ClassRepoProxy

type ClassRepoProxy interface {
	SaveClasses(ctx context.Context, stuId, xnm, xqm string, claInfos []*ClassInfo, scs []*StudentCourse) error
	GetAllClasses(ctx context.Context, stuId, xnm, xqm string) ([]*ClassInfo, error)
	GetSpecificClassInfo(ctx context.Context, classId string) (*ClassInfo, error)
	AddClass(ctx context.Context, classInfo *ClassInfo, sc *StudentCourse, xnm, xqm string) error
	DeleteClass(ctx context.Context, classId string, stuId string, xnm string, xqm string) error
	GetRecycledIds(ctx context.Context, stuId, xnm, xqm string) ([]string, error)
	RemoveClassFromRecycledBin(ctx context.Context, stuId, xnm, xqm, classId string) error
	UpdateClass(ctx context.Context, newClassInfo *ClassInfo, newSc *StudentCourse, stuId, oldClassId, xnm, xqm string) error
	CheckSCIdsExist(ctx context.Context, stuId, classId, xnm, xqm string) bool
	GetAllSchoolClassInfos(ctx context.Context, xnm, xqm string) []*ClassInfo
	CheckClassIdIsInRecycledBin(ctx context.Context, stuId, xnm, xqm, classId string) bool
}

type ClassUsercase

type ClassUsercase struct {
	ClassRepo ClassRepoProxy
	Crawler   ClassCrawler
	// contains filtered or unexported fields
}

func NewClassUsercase

func NewClassUsercase(classRepo ClassRepoProxy, crawler ClassCrawler, log log2.LogerPrinter) *ClassUsercase

func (*ClassUsercase) AddClass

func (cluc *ClassUsercase) AddClass(ctx context.Context, stuId string, info *ClassInfo) error

func (*ClassUsercase) CheckSCIdsExist

func (cluc *ClassUsercase) CheckSCIdsExist(ctx context.Context, stuId, classId, xnm, xqm string) bool

func (*ClassUsercase) DeleteClass

func (cluc *ClassUsercase) DeleteClass(ctx context.Context, classId string, stuId string, xnm string, xqm string) error

func (*ClassUsercase) GetAllSchoolClassInfosToOtherService

func (cluc *ClassUsercase) GetAllSchoolClassInfosToOtherService(ctx context.Context, xnm, xqm string) []*ClassInfo

func (*ClassUsercase) GetClasses

func (cluc *ClassUsercase) GetClasses(ctx context.Context, StuId string, week int64, xnm, xqm string, cookie string) ([]*Class, error)

func (*ClassUsercase) GetRecycledClassInfos

func (cluc *ClassUsercase) GetRecycledClassInfos(ctx context.Context, stuId, xnm, xqm string) ([]*ClassInfo, error)

func (*ClassUsercase) RecoverClassInfo

func (cluc *ClassUsercase) RecoverClassInfo(ctx context.Context, stuId, xnm, xqm, classId string) error

func (*ClassUsercase) SearchClass

func (cluc *ClassUsercase) SearchClass(ctx context.Context, classId string) (*ClassInfo, error)

func (*ClassUsercase) UpdateClass

func (cluc *ClassUsercase) UpdateClass(ctx context.Context, newClassInfo *ClassInfo, newSc *StudentCourse, stuId, oldClassId, xnm, xqm string) error

type StudentAndCourseCacheRepo

type StudentAndCourseCacheRepo interface {
	SaveManyStudentAndCourseToCache(ctx context.Context, key string, classIds []string) error
	AddStudentAndCourseToCache(ctx context.Context, key string, ClassId string) error
	GetClassIdsFromCache(ctx context.Context, key string) ([]string, error)
	GetRecycledClassIds(ctx context.Context, key string) ([]string, error)
	DeleteStudentAndCourseFromCache(ctx context.Context, key string, ClassId string) error
	DeleteAndRecycleClassId(ctx context.Context, deleteKey string, recycleBinKey string, classId string) error
	CheckExists(ctx context.Context, key string, classId string) (bool, error)
	CheckRecycleIdIsExist(ctx context.Context, RecycledBinKey, classId string) bool
	RemoveClassFromRecycledBin(ctx context.Context, RecycledBinKey, classId string) error
}

type StudentAndCourseDBRepo

type StudentAndCourseDBRepo interface {
	SaveManyStudentAndCourseToDB(ctx context.Context, scs []*StudentCourse) error
	SaveStudentAndCourseToDB(ctx context.Context, sc *StudentCourse) error
	GetClassIDsFromSCInDB(ctx context.Context, stuId, xnm, xqm string) ([]string, error)
	DeleteStudentAndCourseInDB(ctx context.Context, ID string) error
	CheckExists(ctx context.Context, xnm, xqm, stuId, classId string) bool
}

type StudentCourse

type StudentCourse struct {
	ID              string `gorm:"primaryKey;column:id" json:"id"`
	StuID           string `gorm:"column:stu_id;not null" json:"stu_id"`                            //学号
	ClaID           string `gorm:"column:cla_id;not null" json:"cla_id"`                            //课程ID
	Year            string `gorm:"column:year;not null;index" json:"year"`                          //学年
	Semester        string `gorm:"column:semester;not null;index" json:"semester"`                  //学期
	IsManuallyAdded bool   `gorm:"column:is_manually_added;default:false" json:"is_manually_added"` //是否为手动添加
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

func (*StudentCourse) BeforeCreate

func (sc *StudentCourse) BeforeCreate(tx *gorm.DB) (err error)

func (*StudentCourse) BeforeUpdate

func (sc *StudentCourse) BeforeUpdate(tx *gorm.DB) (err error)

func (*StudentCourse) TableName

func (sc *StudentCourse) TableName() string

func (*StudentCourse) UpdateID

func (sc *StudentCourse) UpdateID()

type Transaction

type Transaction interface {
	// 下面2个方法配合使用,在InTx方法中执行ORM操作的时候需要使用DB方法获取db!
	InTx(ctx context.Context, fn func(ctx context.Context) error) error
	DB(ctx context.Context) *gorm.DB
}

Directories

Path Synopsis
Package mock_biz is a generated GoMock package.
Package mock_biz is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL