7 changed files with 365 additions and 1 deletions
-
46link_homework/api/v1/record/Record.go
-
8link_homework/internal/cmd/cmd.go
-
110link_homework/internal/controller/record/manageRecord.go
-
1link_homework/internal/logic/logic.go
-
138link_homework/internal/logic/record/record.go
-
24link_homework/internal/model/dto/ToolStruct.go
-
39link_homework/internal/service/record.go
@ -0,0 +1,46 @@ |
|||
package record |
|||
|
|||
import "link_homework/internal/model/dto" |
|||
|
|||
type GetRecordListReq struct { |
|||
Id int `json:"id" orm:"" dc:"作业id"` |
|||
PageNo int `json:"pageNo" dc:"当前页"` |
|||
PageSize int `json:"pageSize" dc:"每页条数"` |
|||
} |
|||
|
|||
// 合并并返回的提交详情所用信息
|
|||
type GetRecordListRes struct { |
|||
Total int `json:"total" dc:"总条数"` |
|||
Jwcode int `json:"jwcode" orm:"db:cms;table:member_info;column:jwcode" dc:"精网号"` |
|||
Name string `json:"name" orm:"db:cms;table:member_info;column:name" dc:"用户名字"` |
|||
DeptId string `json:"deptId" orm:"db:cms;table:member_info;column:deptId" dc:"部门id"` |
|||
DeptName string `json:"deptName" orm:"db:cms;member_info;column:deptName" dc:"部门名"` |
|||
ShopId string `json:"shopId" orm:"db:cms;member_info;column:shopId" dc:"门店id"` |
|||
ShopName string `json:"shopName" orm:"db:cms;member_info;column:shopName" dc:"门店名"` |
|||
Reply []dto.RecordInfo |
|||
} |
|||
|
|||
type GetRecordByConditionReq struct { |
|||
Id int `json:"id" orm:"" dc:"作业id"` |
|||
Jwcode int `json:"jwcode" dc:"精网号"` |
|||
DeptId string `json:"deptId" dc:"部门id"` |
|||
ShopId string `json:"shopId" dc:"门店id"` |
|||
PageNo int `json:"pageNo" dc:"当前页"` |
|||
PageSize int `json:"pageSize" dc:"每页条数"` |
|||
} |
|||
|
|||
/*GetRecordByConditionRes的返回值与GetRecordListRes的一致,所以直接套用*/ |
|||
|
|||
type GetDeptInfoRes struct { |
|||
DeptId string `json:"deptId" orm:"db:cms;table:member_info;column:deptId" dc:"部门id"` |
|||
DeptName string `json:"deptName" orm:"db:cms;member_info;column:deptName" dc:"部门名"` |
|||
} |
|||
|
|||
type GetShopInfoByDeptIdReq struct { |
|||
DeptId string `json:"deptId" dc:"部门id"` |
|||
} |
|||
|
|||
type GetShopInfoByDeptIdRes struct { |
|||
ShopId string `json:"shopId" orm:"db:cms;member_info;column:shopId" dc:"门店id"` |
|||
ShopName string `json:"shopName" orm:"db:cms;member_info;column:shopName" dc:"门店名"` |
|||
} |
@ -0,0 +1,110 @@ |
|||
package record |
|||
|
|||
import ( |
|||
"github.com/gogf/gf/v2/net/ghttp" |
|||
"link_homework/api/v1/record" |
|||
"link_homework/internal/model/dto" |
|||
"link_homework/internal/service" |
|||
) |
|||
|
|||
type ManageRecord struct{} |
|||
|
|||
func NewManageRecord() *ManageRecord { |
|||
return &ManageRecord{} |
|||
} |
|||
|
|||
// 查询所有提交记录
|
|||
func (m *ManageRecord) GetRecordList(r *ghttp.Request) { |
|||
var req record.GetRecordListReq |
|||
if err := r.Parse(&req); err != nil { |
|||
r.Response.WriteJsonExit(dto.Result{ |
|||
Code: 400, |
|||
Message: err.Error(), |
|||
}) |
|||
} |
|||
groupId := req.Id |
|||
pageNo := req.PageNo |
|||
pageSize := req.PageSize |
|||
result, err := service.Record().GetRecordList(r.Context(), groupId, pageNo, pageSize) |
|||
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 (m *ManageRecord) GetRecordByCondition(r *ghttp.Request) { |
|||
var req record.GetRecordByConditionReq |
|||
if err := r.Parse(&req); err != nil { |
|||
r.Response.WriteJsonExit(dto.Result{ |
|||
Code: 400, |
|||
Message: err.Error(), |
|||
}) |
|||
} |
|||
groupId := req.Id |
|||
jwcode := req.Jwcode |
|||
deptId := req.DeptId |
|||
shopId := req.ShopId |
|||
pageNo := req.PageNo |
|||
pageSize := req.PageSize |
|||
result, err := service.Record().GetRecordByCondition(r.Context(), groupId, jwcode, deptId, shopId, pageNo, pageSize) |
|||
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 (m *ManageRecord) GetDeptInfo(r *ghttp.Request) { |
|||
result, err := service.Record().GetDeptInfo(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 (m *ManageRecord) GetShopInfo(r *ghttp.Request) { |
|||
var req record.GetShopInfoByDeptIdReq |
|||
if err := r.Parse(&req); err != nil { |
|||
r.Response.WriteJsonExit(dto.Result{ |
|||
Code: 400, |
|||
Message: err.Error(), |
|||
}) |
|||
} |
|||
deptId := req.DeptId |
|||
result, err := service.Record().GetShopInfoByDeptId(r.Context(), deptId) |
|||
if err != nil { |
|||
r.Response.WriteJsonExit(dto.Result{ |
|||
Code: 400, |
|||
Message: err.Error(), |
|||
}) |
|||
} |
|||
r.Response.WriteJsonExit(dto.Result{ |
|||
Code: 200, |
|||
Message: "success", |
|||
Data: result, |
|||
}) |
|||
|
|||
} |
@ -0,0 +1,138 @@ |
|||
package record |
|||
|
|||
import ( |
|||
"context" |
|||
"errors" |
|||
"fmt" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
pkgRecord "link_homework/api/v1/record" |
|||
"link_homework/internal/dao" |
|||
"link_homework/internal/model/dto" |
|||
"link_homework/internal/service" |
|||
) |
|||
|
|||
type sRecord struct{} |
|||
|
|||
func init() { |
|||
service.RegisterRecord(&sRecord{}) |
|||
} |
|||
|
|||
func NewRecord() *sRecord { |
|||
return &sRecord{} |
|||
} |
|||
|
|||
// 无条件全查
|
|||
func (s *sRecord) GetRecordList(ctx context.Context, groupId, pageNo, pageSize int) (record []pkgRecord.GetRecordListRes, err error) { |
|||
//从record表中查询出jwcode,根据group_id
|
|||
err = dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode"). |
|||
Page(pageNo, pageSize).Scan(&record) |
|||
if err != nil { |
|||
panic("无条件查jwcode失败") |
|||
} |
|||
|
|||
fmt.Println(record) |
|||
//根据jwcode在member_info表中查询姓名(name), 部门id(deptId), 部门名(deptName), 门店id(shopId), 门店名(shopName)
|
|||
for i, info := range record { |
|||
err = g.DB("cms").Model("member_info").Fields("jwcode", "name", "deptId", "deptName", "shopId", "shopName"). |
|||
Where("jwcode", info.Jwcode).Scan(&record[i]) |
|||
if err != nil { |
|||
panic("无条件根据jwcode查member_info表失败") |
|||
} |
|||
total, err1 := dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode").Count() |
|||
if err1 != nil { |
|||
return |
|||
} |
|||
record[i].Total = total |
|||
//根据jwcode,groupId在record表中查询最新的提交记录进行存放
|
|||
var recordInfo []dto.RecordInfo |
|||
err = dao.ActivityInteractiveRecord.Ctx(ctx).Fields("content", "content_title", "updated_at", "form_id"). |
|||
Where("jwcode", info.Jwcode).Where("group_id", groupId).Group("form_id").Order("updated_at desc").Scan(&recordInfo) //不是最新的,需要再改
|
|||
for i, title := range recordInfo { |
|||
err = dao.ActivityInteractiveForm.Ctx(ctx).Fields("description", "type").Where("id", title.FormId).Scan(&recordInfo[i]) |
|||
} |
|||
record[i].Reply = recordInfo |
|||
fmt.Println(record) |
|||
} |
|||
return |
|||
} |
|||
|
|||
// 根据条件查询
|
|||
func (s *sRecord) GetRecordByCondition(ctx context.Context, groupId, jwcode int, deptId, shopId string, pageNo, pageSize int) (record []pkgRecord.GetRecordListRes, err error) { |
|||
//全查
|
|||
recordList, err := s.GetRecordList(ctx, groupId, pageNo, pageSize) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
//判断传来的jwcode, deptId, shopId是否为空,根据情况进行不同的筛选
|
|||
if jwcode == 0 { //没有传jwcode
|
|||
if deptId == "" && shopId == "" { //000
|
|||
return recordList, nil |
|||
} else if deptId != "" && shopId == "" { //010
|
|||
for _, info := range recordList { |
|||
if info.DeptId == deptId { |
|||
record = append(record, info) |
|||
} |
|||
} |
|||
if record == nil { |
|||
return nil, errors.New("只部门没有查询到相关记录") |
|||
} |
|||
return record, err |
|||
} else if deptId != "" && shopId != "" { //011
|
|||
for _, info := range recordList { |
|||
if info.DeptId == deptId && info.ShopId == shopId { |
|||
record = append(record, info) |
|||
} |
|||
} |
|||
if record == nil { |
|||
return nil, errors.New("部门,门店 没有查询到相关记录") |
|||
} |
|||
return record, err |
|||
} |
|||
} else { //传了jwcode
|
|||
if deptId == "" && shopId == "" { //100
|
|||
for _, info := range recordList { |
|||
if info.Jwcode == jwcode { |
|||
record = append(record, info) |
|||
} |
|||
} |
|||
if record == nil { |
|||
return nil, errors.New("只精网号没有查询到相关记录") |
|||
} |
|||
return record, err |
|||
} else if deptId != "" && shopId == "" { //110
|
|||
for _, info := range recordList { |
|||
if info.Jwcode == jwcode && info.DeptId == deptId { |
|||
record = append(record, info) |
|||
} |
|||
} |
|||
if record == nil { |
|||
return nil, errors.New("精网号,部门 没有查询到相关记录") |
|||
} |
|||
return record, err |
|||
} else if deptId != "" && shopId != "" { //111
|
|||
for _, info := range recordList { |
|||
if info.Jwcode == jwcode && info.DeptId == deptId && info.ShopId == shopId { |
|||
record = append(record, info) |
|||
} |
|||
} |
|||
if record == nil { |
|||
return nil, errors.New("精网号,部门,门店 没有查询到相关记录") |
|||
} |
|||
return record, err |
|||
} |
|||
} |
|||
return nil, errors.New("检查一下穿的参数是否正常") |
|||
} |
|||
|
|||
// 查询部门信息
|
|||
func (s *sRecord) GetDeptInfo(ctx context.Context) (depts []pkgRecord.GetDeptInfoRes, err error) { |
|||
err = g.DB("cms").Model("member_info").Fields("deptId", "deptName").Group("deptId").Scan(&depts) |
|||
return |
|||
} |
|||
|
|||
// 根据部门信息查询门店信息
|
|||
func (s *sRecord) GetShopInfoByDeptId(ctx context.Context, deptId string) (shops []pkgRecord.GetShopInfoByDeptIdRes, err error) { |
|||
err = g.DB("cms").Model("member_info").Fields("shopId", "shopName"). |
|||
Where("deptId", deptId).Group("shopId").Scan(&shops) |
|||
return |
|||
} |
@ -0,0 +1,24 @@ |
|||
package dto |
|||
|
|||
import "github.com/gogf/gf/v2/os/gtime" |
|||
|
|||
// 从cms库中查询用户信息
|
|||
type MemberInfo struct { |
|||
Jwcode int `json:"jwcode" orm:"db:cms;table:member_info;column:jwcode" dc:"精网号"` |
|||
Name string `json:"name" orm:"db:cms;table:member_info;column:name" dc:"用户名字"` |
|||
DeptId string `json:"deptId" orm:"db:cms;table:member_info;column:deptId" dc:"部门id"` |
|||
DeptName string `json:"deptName" orm:"db:cms;member_info;column:deptName" dc:"部门名"` |
|||
ShopId string `json:"shopId" orm:"db:cms;member_info;column:shopId" dc:"门店id"` |
|||
ShopName string `json:"shopName" orm:"db:cms;member_info;column:shopName" dc:"门店名"` |
|||
} |
|||
|
|||
// 从live库里查询作业信息
|
|||
type RecordInfo struct { |
|||
//Jwcode int `json:"jwcode" orm:"db:default;table:activity_interactive_record;column:jwcode" dc:"精网号"`
|
|||
FormId int `json:"formId" orm:"db:default;table:activity_interactive_record;column:form_id" dc:"题目id"` |
|||
Type int `json:"type" orm:"db:default;table:activity_interactive_form;column:type" dc:"题目类型"` |
|||
Description string `json:"formTitle" orm:"db:default;table:activity_interactive_form;column:description" dc:"题目"` |
|||
ContentTitle string `json:"contentTitle" orm:"db:default;table:activity_interactive_record;column:content_title" dc:"作答标题"` |
|||
Content string `json:"content" orm:"db:default;table:activity_interactive_record;column:content" dc:"作答内容"` |
|||
UpdatedAt gtime.Time `json:"submitTime" orm:"db:default;table:activity_interactive_record;column:updated_at" dc:"提交时间/更新时间"` |
|||
} |
@ -0,0 +1,39 @@ |
|||
// ================================================================================
|
|||
// 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" |
|||
pkgRecord "link_homework/api/v1/record" |
|||
) |
|||
|
|||
type ( |
|||
IRecord interface { |
|||
// 无条件全查
|
|||
GetRecordList(ctx context.Context, groupId int, pageNo int, pageSize int) (record []pkgRecord.GetRecordListRes, err error) |
|||
// 根据条件查询
|
|||
GetRecordByCondition(ctx context.Context, groupId int, jwcode int, deptId string, shopId string, pageNo int, pageSize int) (record []pkgRecord.GetRecordListRes, err error) |
|||
// 查询部门信息
|
|||
GetDeptInfo(ctx context.Context) (depts []pkgRecord.GetDeptInfoRes, err error) |
|||
// 根据部门信息查询门店信息
|
|||
GetShopInfoByDeptId(ctx context.Context, deptId string) (shops []pkgRecord.GetShopInfoByDeptIdRes, err error) |
|||
} |
|||
) |
|||
|
|||
var ( |
|||
localRecord IRecord |
|||
) |
|||
|
|||
func Record() IRecord { |
|||
if localRecord == nil { |
|||
panic("implement not found for interface IRecord, forgot register?") |
|||
} |
|||
return localRecord |
|||
} |
|||
|
|||
func RegisterRecord(i IRecord) { |
|||
localRecord = i |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue