8 changed files with 13 additions and 181 deletions
-
27link_homework/api/v1/ClientPage/ClientPage.go
-
3link_homework/internal/cmd/cmd.go
-
53link_homework/internal/controller/clientPage/clientPage.go
-
16link_homework/internal/controller/record/manageRecord.go
-
47link_homework/internal/logic/homework/homeworkList.go
-
1link_homework/internal/logic/logic.go
-
14link_homework/internal/logic/record/record.go
-
33link_homework/internal/service/homework.go
@ -1,27 +0,0 @@ |
|||||
package ClientPage |
|
||||
|
|
||||
import ( |
|
||||
"github.com/gogf/gf/v2/os/gtime" |
|
||||
) |
|
||||
|
|
||||
type GetHomeworkListRse struct { |
|
||||
Id int `json:"id" 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
|
|
@ -1,53 +0,0 @@ |
|||||
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.Homework().GetHomeworkList(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(), |
|
||||
}) |
|
||||
} |
|
||||
groupId := req.Id |
|
||||
result, err := service.Homework().GetHomeworkQuestion(r.Context(), groupId) |
|
||||
if err != nil { |
|
||||
r.Response.WriteJsonExit(dto.Result{ |
|
||||
Code: 400, |
|
||||
Message: err.Error(), |
|
||||
}) |
|
||||
} |
|
||||
r.Response.WriteJsonExit(dto.Result{ |
|
||||
Code: 200, |
|
||||
Message: "success", |
|
||||
Data: result, |
|
||||
}) |
|
||||
} |
|
@ -1,47 +0,0 @@ |
|||||
package homework |
|
||||
|
|
||||
import ( |
|
||||
"context" |
|
||||
"fmt" |
|
||||
"github.com/gogf/gf/v2/os/gtime" |
|
||||
"link_homework/api/v1/ClientPage" |
|
||||
"link_homework/internal/dao" |
|
||||
"link_homework/internal/service" |
|
||||
) |
|
||||
|
|
||||
type sHomework struct{} |
|
||||
|
|
||||
func init() { |
|
||||
service.RegisterHomework(&sHomework{}) |
|
||||
} |
|
||||
|
|
||||
func (s *sHomework) GetHomeworkList(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", item.Id).Count() |
|
||||
if err1 != nil { |
|
||||
fmt.Println("题目数查询失败:", err1, num) |
|
||||
return |
|
||||
} |
|
||||
homeworkList[i].Submit = count / num |
|
||||
} |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func (s *sHomework) 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 |
|
||||
} |
|
@ -1,6 +1,5 @@ |
|||||
package logic |
package logic |
||||
|
|
||||
import ( |
import ( |
||||
_ "link_homework/internal/logic/homework" |
|
||||
_ "link_homework/internal/logic/record" |
_ "link_homework/internal/logic/record" |
||||
) |
) |
@ -1,33 +0,0 @@ |
|||||
// ================================================================================
|
|
||||
// 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 ( |
|
||||
IHomework interface { |
|
||||
GetHomeworkList(ctx context.Context) (homeworkList []ClientPage.GetHomeworkListRse, err error) |
|
||||
GetHomeworkQuestion(ctx context.Context, groupId int) (questions []ClientPage.GetHomeworkQuestionRes, err error) |
|
||||
} |
|
||||
) |
|
||||
|
|
||||
var ( |
|
||||
localHomework IHomework |
|
||||
) |
|
||||
|
|
||||
func Homework() IHomework { |
|
||||
if localHomework == nil { |
|
||||
panic("implement not found for interface IHomework, forgot register?") |
|
||||
} |
|
||||
return localHomework |
|
||||
} |
|
||||
|
|
||||
func RegisterHomework(i IHomework) { |
|
||||
localHomework = i |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue