Compare commits

...

7 Commits

  1. 38
      link_homework/api/v1/ClientPage/ClientPage.go
  2. 1
      link_homework/api/v1/hello.go
  3. 2
      link_homework/hack/config.yaml
  4. 45
      link_homework/internal/cmd/cmd.go
  5. 76
      link_homework/internal/controller/clientPage/clientPage.go
  6. 24
      link_homework/internal/dao/internal/activity_interactive_form.go
  7. 24
      link_homework/internal/dao/internal/activity_interactive_group.go
  8. 24
      link_homework/internal/dao/internal/activity_interactive_record.go
  9. 22
      link_homework/internal/dao/internal/fx_article.go
  10. 24
      link_homework/internal/dao/internal/live.go
  11. 22
      link_homework/internal/dao/internal/member_info.go
  12. 87
      link_homework/internal/logic/client/client.go
  13. 0
      link_homework/internal/logic/homework/.gitkeep
  14. 4
      link_homework/internal/logic/logic.go
  15. 34
      link_homework/internal/service/client.go
  16. 8
      link_homework/internal/service/middleware.go
  17. 2
      link_homework/manifest/config/config.yaml

38
link_homework/api/v1/ClientPage/ClientPage.go

@ -0,0 +1,38 @@
package ClientPage
import (
"github.com/gogf/gf/v2/os/gtime"
)
type GetHomeworkListRse struct {
Id int `json:"groupId" orm:"table:activity_interactive_group;column:id" dc:"id" `
Name string `json:"name" orm:"table:activity_interactive_group;column:name" dc:"作业题目"`
EndDate *gtime.Time `json:"endData" orm:"table:activity_interactive_group;column:end_date;time_format:yy-MM-dd" dc:"作业截止时间"`
Submit int `json:"submit"`
}
type GetHomeworkQuestionReq struct {
Id int `json:"id" dc:"作业id"`
}
type GetHomeworkQuestionRes struct {
Id int `json:"id" orm:"table:activity_interactive_form;column:id" dc:"题目id"`
Name string `json:"name" orm:"table:activity_interactive_form;column:name" dc:"作业名称"`
Description string `json:"description" orm:"table:activity_interactive_form;column:description" dc:"作业题目名字"`
Content string `json:"content" orm:"table:activity_interactive_form;column:content" dc:"题目内容"`
Status int `json:"status"`
Type int `json:"type" orm:"table:activity_interactive_form;column:type" dc:"题目类型"`
}
//需要id(group_id)(form表),查id,form.name是作业的题目,form.description是作业题目的名字,content, status,type
type CommitHomeworkReq struct {
GroupId int `json:"id" v:"required:#作业id不能为空" dc:"作业id"`
CommitedAnswer []CommitAnswer `json:"homework" dc:"传过来的答案"`
}
type CommitAnswer struct {
Id int `json:"id" orm:"table:activity_interactive_record;column:form_id" dc:"作业题目id"`
Answer []string `json:"answer" dc:"作业答案,包含两部分,第一部分是题目,第二部分是答案,使用','分割的"`
Type int `json:"type" dc:"题目类型,1:单选,2:多选,3:简答"`
}

1
link_homework/api/v1/hello.go

@ -1 +0,0 @@
package v1

2
link_homework/hack/config.yaml

@ -5,7 +5,7 @@ gfcli:
gen:
dao:
- link: "mysql:live:p4jMAMShNM8HTrbX@tcp(39.101.133.168:3306)/live?charset=utf8mb4&parseTime=True&loc=Local"
group: "live"
group: "default"
tables: "live, activity_interactive_form, activity_interactive_group, activity_interactive_record"
descriptionTag: true
- link: "mysql:cms:AF42R3ib6YkFaemm@tcp(39.101.133.168:3306)/cms?charset=utf8mb4&parseTime=True&loc=Local"

45
link_homework/internal/cmd/cmd.go

@ -2,10 +2,11 @@ package cmd
import (
"context"
"github.com/goflyfox/gtoken/gtoken"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"link_homework/internal/controller/clientPage"
"link_homework/internal/logic/middleware"
)
var (
@ -17,32 +18,36 @@ var (
s := g.Server()
//后台
//启动gtoken
// 创建一个GfToken对象,用于处理用户登录、登出、权限验证等操作
gfToken := &gtoken.GfToken{
// 设置登录路径,即用户登录接口登入成功后会获得一个Token
LoginPath: "/login",
//// 设置登录前执行的函数,在用户登录之前会调用这个函数进行一些预处理,比如验证用户名和密码等。
//LoginBeforeFunc: loginFunc, //手动编写 没有同时配置登入路径,登入方法,登出路径启动时会报错
// 设置登出路径,即用户登出接口登入成功后会删除Token
LogoutPath: "/user/logout",
//// 设置需要拦截的路径,按照前缀拦截,所有以/user或/system开头的路径都需要进行Token认证。
//AuthPaths: g.SliceStr{"/user", "/system"},
//// 设置不需要拦截的路径,所有以/user/info或/system/user/开头的路径都不需要进行Token认证。
//AuthExcludePaths: g.SliceStr{"/user/info", "/system/user/*"},
//// 开启全局拦截,默认关闭,如果设置为true,则所有请求都会经过Token认证中间件,如果设置为false,则只有指定路径的请求会经过Token认证中间件。
//GlobalMiddleware: true,
}
////启动gtoken
//// 创建一个GfToken对象,用于处理用户登录、登出、权限验证等操作
//gfToken := &gtoken.GfToken{
// // 设置登录路径,即用户登录接口登入成功后会获得一个Token
// LoginPath: "/login",
// //// 设置登录前执行的函数,在用户登录之前会调用这个函数进行一些预处理,比如验证用户名和密码等。
// //LoginBeforeFunc: loginFunc, //手动编写 没有同时配置登入路径,登入方法,登出路径启动时会报错
// // 设置登出路径,即用户登出接口登入成功后会删除Token
// LogoutPath: "/user/logout",
// //// 设置需要拦截的路径,按照前缀拦截,所有以/user或/system开头的路径都需要进行Token认证。
// //AuthPaths: g.SliceStr{"/user", "/system"},
// //// 设置不需要拦截的路径,所有以/user/info或/system/user/开头的路径都不需要进行Token认证。
// //AuthExcludePaths: g.SliceStr{"/user/info", "/system/user/*"},
// //// 开启全局拦截,默认关闭,如果设置为true,则所有请求都会经过Token认证中间件,如果设置为false,则只有指定路径的请求会经过Token认证中间件。
// //GlobalMiddleware: true,
//}
s.Group("/api/homework_manage", func(group *ghttp.RouterGroup) {
//group.Middleware(middleware.MiddlewareIsLogin)
gfToken.Middleware(ctx, group)
group.Middleware(middleware.MiddlewareIsLogin)
//gfToken.Middleware(ctx, group)
//直接写接口,不用再分组
})
//客户端
s.Group("/api/homework_client", func(group *ghttp.RouterGroup) {
group.Middleware(middleware.MiddlewareCORS)
//group.Middleware(middleware.MiddlewareIsLogin)
gfToken.Middleware(ctx, group)
//gfToken.Middleware(ctx, group)
//直接写接口,不用再分组
group.POST("/gethomeworklist", clientPage.NewClientPage().GetHomeworkList)
group.POST("/gethomeworkquestion", clientPage.NewClientPage().GetHomeworkQuestion)
group.POST("/commithomework", clientPage.NewClientPage().CommitHomework)
})
s.Run()

76
link_homework/internal/controller/clientPage/clientPage.go

@ -1 +1,77 @@
package clientPage
import (
"github.com/gogf/gf/v2/net/ghttp"
CPage "link_homework/api/v1/ClientPage"
"link_homework/internal/model/dto"
"link_homework/internal/service"
)
type ClientPage struct{}
func NewClientPage() *ClientPage {
return &ClientPage{}
}
// 查询作业列表
func (c *ClientPage) GetHomeworkList(r *ghttp.Request) {
//请求中不需要携带任何参数
result, err := service.Client().ClientGetHomeworkList(r.Context())
if err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
r.Response.WriteJsonExit(dto.Result{
Code: 200,
Message: "success",
Data: result,
})
}
// 查询题目列表
func (c *ClientPage) GetHomeworkQuestion(r *ghttp.Request) {
var req CPage.GetHomeworkQuestionReq
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
result, err := service.Client().GetHomeworkQuestion(r.Context(), req.Id)
if err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
r.Response.WriteJsonExit(dto.Result{
Code: 200,
Message: "success",
Data: result,
})
}
func (c *ClientPage) CommitHomework(r *ghttp.Request) {
var jwcode int = 90038794
var req CPage.CommitHomeworkReq
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
err := service.Client().CommitHomework(r.Context(), req, jwcode)
if err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
r.Response.WriteJsonExit(dto.Result{
Code: 200,
Message: "提交作业成功",
})
}

24
link_homework/internal/dao/internal/activity_interactive_form.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// ActivityInteractiveFormDao is the data access object for the table activity_interactive_form.
// ActivityInteractiveFormDao is the data access object for table activity_interactive_form.
type ActivityInteractiveFormDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns ActivityInteractiveFormColumns // columns contains all the column names of Table for convenient usage.
}
// ActivityInteractiveFormColumns defines and stores column names for the table activity_interactive_form.
// ActivityInteractiveFormColumns defines and stores column names for table activity_interactive_form.
type ActivityInteractiveFormColumns struct {
Id string //
Name string // 名称
@ -32,7 +32,7 @@ type ActivityInteractiveFormColumns struct {
GroupId string // 问题分组id
}
// activityInteractiveFormColumns holds the columns for the table activity_interactive_form.
// activityInteractiveFormColumns holds the columns for table activity_interactive_form.
var activityInteractiveFormColumns = ActivityInteractiveFormColumns{
Id: "id",
Name: "name",
@ -49,42 +49,42 @@ var activityInteractiveFormColumns = ActivityInteractiveFormColumns{
// NewActivityInteractiveFormDao creates and returns a new DAO object for table data access.
func NewActivityInteractiveFormDao() *ActivityInteractiveFormDao {
return &ActivityInteractiveFormDao{
group: "live",
group: "default",
table: "activity_interactive_form",
columns: activityInteractiveFormColumns,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ActivityInteractiveFormDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *ActivityInteractiveFormDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *ActivityInteractiveFormDao) Columns() ActivityInteractiveFormColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *ActivityInteractiveFormDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ActivityInteractiveFormDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ActivityInteractiveFormDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

24
link_homework/internal/dao/internal/activity_interactive_group.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// ActivityInteractiveGroupDao is the data access object for the table activity_interactive_group.
// ActivityInteractiveGroupDao is the data access object for table activity_interactive_group.
type ActivityInteractiveGroupDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns ActivityInteractiveGroupColumns // columns contains all the column names of Table for convenient usage.
}
// ActivityInteractiveGroupColumns defines and stores column names for the table activity_interactive_group.
// ActivityInteractiveGroupColumns defines and stores column names for table activity_interactive_group.
type ActivityInteractiveGroupColumns struct {
Id string //
Name string // 表单名称
@ -32,7 +32,7 @@ type ActivityInteractiveGroupColumns struct {
EndDate string // 作业结束时间
}
// activityInteractiveGroupColumns holds the columns for the table activity_interactive_group.
// activityInteractiveGroupColumns holds the columns for table activity_interactive_group.
var activityInteractiveGroupColumns = ActivityInteractiveGroupColumns{
Id: "id",
Name: "name",
@ -49,42 +49,42 @@ var activityInteractiveGroupColumns = ActivityInteractiveGroupColumns{
// NewActivityInteractiveGroupDao creates and returns a new DAO object for table data access.
func NewActivityInteractiveGroupDao() *ActivityInteractiveGroupDao {
return &ActivityInteractiveGroupDao{
group: "live",
group: "default",
table: "activity_interactive_group",
columns: activityInteractiveGroupColumns,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ActivityInteractiveGroupDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *ActivityInteractiveGroupDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *ActivityInteractiveGroupDao) Columns() ActivityInteractiveGroupColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *ActivityInteractiveGroupDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ActivityInteractiveGroupDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ActivityInteractiveGroupDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

24
link_homework/internal/dao/internal/activity_interactive_record.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// ActivityInteractiveRecordDao is the data access object for the table activity_interactive_record.
// ActivityInteractiveRecordDao is the data access object for table activity_interactive_record.
type ActivityInteractiveRecordDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns ActivityInteractiveRecordColumns // columns contains all the column names of Table for convenient usage.
}
// ActivityInteractiveRecordColumns defines and stores column names for the table activity_interactive_record.
// ActivityInteractiveRecordColumns defines and stores column names for table activity_interactive_record.
type ActivityInteractiveRecordColumns struct {
Id string //
Jwcode string //
@ -30,7 +30,7 @@ type ActivityInteractiveRecordColumns struct {
ContentTitle string //
}
// activityInteractiveRecordColumns holds the columns for the table activity_interactive_record.
// activityInteractiveRecordColumns holds the columns for table activity_interactive_record.
var activityInteractiveRecordColumns = ActivityInteractiveRecordColumns{
Id: "id",
Jwcode: "jwcode",
@ -45,42 +45,42 @@ var activityInteractiveRecordColumns = ActivityInteractiveRecordColumns{
// NewActivityInteractiveRecordDao creates and returns a new DAO object for table data access.
func NewActivityInteractiveRecordDao() *ActivityInteractiveRecordDao {
return &ActivityInteractiveRecordDao{
group: "live",
group: "default",
table: "activity_interactive_record",
columns: activityInteractiveRecordColumns,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ActivityInteractiveRecordDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *ActivityInteractiveRecordDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *ActivityInteractiveRecordDao) Columns() ActivityInteractiveRecordColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *ActivityInteractiveRecordDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ActivityInteractiveRecordDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ActivityInteractiveRecordDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

22
link_homework/internal/dao/internal/fx_article.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// FxArticleDao is the data access object for the table fx_article.
// FxArticleDao is the data access object for table fx_article.
type FxArticleDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns FxArticleColumns // columns contains all the column names of Table for convenient usage.
}
// FxArticleColumns defines and stores column names for the table fx_article.
// FxArticleColumns defines and stores column names for table fx_article.
type FxArticleColumns struct {
Id string //
Title string // 标题
@ -117,7 +117,7 @@ type FxArticleColumns struct {
VideoType string // 视频类型 1 横屏 2 竖屏
}
// fxArticleColumns holds the columns for the table fx_article.
// fxArticleColumns holds the columns for table fx_article.
var fxArticleColumns = FxArticleColumns{
Id: "id",
Title: "title",
@ -225,36 +225,36 @@ func NewFxArticleDao() *FxArticleDao {
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *FxArticleDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *FxArticleDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *FxArticleDao) Columns() FxArticleColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *FxArticleDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *FxArticleDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *FxArticleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

24
link_homework/internal/dao/internal/live.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// LiveDao is the data access object for the table live.
// LiveDao is the data access object for table live.
type LiveDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns LiveColumns // columns contains all the column names of Table for convenient usage.
}
// LiveColumns defines and stores column names for the table live.
// LiveColumns defines and stores column names for table live.
type LiveColumns struct {
Id string //
Jwcode string //
@ -106,7 +106,7 @@ type LiveColumns struct {
JoinClassButton string // 进群按钮 1:开启
}
// liveColumns holds the columns for the table live.
// liveColumns holds the columns for table live.
var liveColumns = LiveColumns{
Id: "id",
Jwcode: "jwcode",
@ -197,42 +197,42 @@ var liveColumns = LiveColumns{
// NewLiveDao creates and returns a new DAO object for table data access.
func NewLiveDao() *LiveDao {
return &LiveDao{
group: "live",
group: "default",
table: "live",
columns: liveColumns,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *LiveDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *LiveDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *LiveDao) Columns() LiveColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *LiveDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *LiveDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *LiveDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

22
link_homework/internal/dao/internal/member_info.go

@ -11,14 +11,14 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
// MemberInfoDao is the data access object for the table member_info.
// MemberInfoDao is the data access object for table member_info.
type MemberInfoDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
group string // group is the database configuration group name of current DAO.
columns MemberInfoColumns // columns contains all the column names of Table for convenient usage.
}
// MemberInfoColumns defines and stores column names for the table member_info.
// MemberInfoColumns defines and stores column names for table member_info.
type MemberInfoColumns struct {
Id string //
Jwcode string //
@ -60,7 +60,7 @@ type MemberInfoColumns struct {
CreateTime string // 账号注册时间
}
// memberInfoColumns holds the columns for the table member_info.
// memberInfoColumns holds the columns for table member_info.
var memberInfoColumns = MemberInfoColumns{
Id: "id",
Jwcode: "jwcode",
@ -111,36 +111,36 @@ func NewMemberInfoDao() *MemberInfoDao {
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *MemberInfoDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
// Table returns the table name of current dao.
func (dao *MemberInfoDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
// Columns returns all column names of current dao.
func (dao *MemberInfoDao) Columns() MemberInfoColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
// Group returns the configuration group name of database of current dao.
func (dao *MemberInfoDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *MemberInfoDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *MemberInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)

87
link_homework/internal/logic/client/client.go

@ -0,0 +1,87 @@
package client
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"link_homework/api/v1/ClientPage"
"link_homework/internal/dao"
"link_homework/internal/service"
)
type sClient struct{}
func init() {
service.RegisterClient(&sClient{})
}
func (s *sClient) ClientGetHomeworkList(ctx context.Context) (homeworkList []ClientPage.GetHomeworkListRse, err error) {
var jwcode = 90038794 //需要从token中获取当前的数据
err = dao.ActivityInteractiveGroup.Ctx(ctx).Fields("id", "name", "DATE_FORMAT(end_date, '%Y-%m-%d') as end_date").
Where("end_date>?", gtime.Now()).OrderDesc("end_date").Scan(&homeworkList)
if err != nil {
fmt.Println("作业列表查询失败:", err)
return
}
for i, item := range homeworkList {
var count int
count, err = dao.ActivityInteractiveRecord.Ctx(ctx).Where("group_id=?", item.Id).Where("jwcode", jwcode).Count() //只有精网号和作业id查出来的结果是所需要的结果的题目数倍数
if err != nil {
fmt.Println("提交记录数查询失败:", err)
return
}
num, err1 := dao.ActivityInteractiveForm.Ctx(ctx).Where("group_id", item.Id).Count()
if err1 != nil {
fmt.Println("题目数查询失败:", err1)
return
}
homeworkList[i].Submit = count / num
}
return
}
func (s *sClient) GetHomeworkQuestion(ctx context.Context, groupId int) (questions []ClientPage.GetHomeworkQuestionRes, err error) {
err = dao.ActivityInteractiveForm.Ctx(ctx).Fields("id", "name", "content", "status", "type").
Where("group_id", groupId).Scan(&questions)
return
}
func (s *sClient) CommitHomework(ctx context.Context, req ClientPage.CommitHomeworkReq, jwcode int) (err error) {
//req中需要有:作业id,提交的每一个题的答案,每一个提的类型
for _, answer := range req.CommitedAnswer {
if answer.Type == 1 { //单选或者多选
_, err := dao.ActivityInteractiveRecord.Ctx(ctx).Data(g.Map{
"jwcode": jwcode,
"form_id": answer.Id,
"group_id": req.GroupId,
"content": answer.Answer[0],
}).Insert()
if err != nil {
return err
}
} else if answer.Type == 2 { //多选
_, err := dao.ActivityInteractiveRecord.Ctx(ctx).Data(g.Map{
"jwcode": jwcode,
"form_id": answer.Id,
"group_id": req.GroupId,
"content": answer.Answer,
}).Insert()
if err != nil {
return err
}
} else if answer.Type == 3 { //简答
_, err := dao.ActivityInteractiveRecord.Ctx(ctx).Data(g.Map{
"jwcode": jwcode,
"form_id": answer.Id,
"group_id": req.GroupId,
"content_title": answer.Answer[0],
"content": answer.Answer[1],
}).Insert()
if err != nil {
return err
}
}
}
return
}

0
link_homework/internal/logic/homework/.gitkeep

4
link_homework/internal/logic/logic.go

@ -1 +1,5 @@
package logic
import (
_ "link_homework/internal/logic/client"
)

34
link_homework/internal/service/client.go

@ -0,0 +1,34 @@
// ================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
"link_homework/api/v1/ClientPage"
)
type (
IClient interface {
ClientGetHomeworkList(ctx context.Context) (homeworkList []ClientPage.GetHomeworkListRse, err error)
GetHomeworkQuestion(ctx context.Context, groupId int) (questions []ClientPage.GetHomeworkQuestionRes, err error)
CommitHomework(ctx context.Context, req ClientPage.CommitHomeworkReq, jwcode int) (err error)
}
)
var (
localClient IClient
)
func Client() IClient {
if localClient == nil {
panic("implement not found for interface IClient, forgot register?")
}
return localClient
}
func RegisterClient(i IClient) {
localClient = i
}

8
link_homework/internal/service/middleware.go

@ -0,0 +1,8 @@
// ================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

2
link_homework/manifest/config/config.yaml

@ -17,5 +17,3 @@ database:
cms:
link: "mysql:cms:AF42R3ib6YkFaemm@tcp(39.101.133.168:3306)/cms?charset=utf8mb4&parseTime=True&loc=Local"
debug: true
# redis暂不配置,记得加
Loading…
Cancel
Save