|
@ -2,7 +2,9 @@ package record |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"encoding/json" |
|
|
"errors" |
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
pkgRecord "link_homework/api/v1/record" |
|
|
pkgRecord "link_homework/api/v1/record" |
|
|
"link_homework/internal/dao" |
|
|
"link_homework/internal/dao" |
|
@ -43,7 +45,7 @@ func (s *sRecord) GetRecordList(ctx context.Context, groupId, pageNo, pageSize i |
|
|
} |
|
|
} |
|
|
total, err1 := dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode").Count() |
|
|
total, err1 := dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode").Count() |
|
|
if err1 != nil { |
|
|
if err1 != nil { |
|
|
return |
|
|
|
|
|
|
|
|
return nil, errors.New("无条件查询总数失败") |
|
|
} |
|
|
} |
|
|
record[i].Total = total |
|
|
record[i].Total = total |
|
|
//根据jwcode,groupId在record表中查询最新的提交记录进行存放
|
|
|
//根据jwcode,groupId在record表中查询最新的提交记录进行存放
|
|
@ -51,12 +53,12 @@ func (s *sRecord) GetRecordList(ctx context.Context, groupId, pageNo, pageSize i |
|
|
err = dao.ActivityInteractiveRecord.Ctx(ctx).Fields("content", "content_title", "updated_at", "form_id"). |
|
|
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) |
|
|
Where("jwcode", info.Jwcode).Where("group_id", groupId).Group("form_id").Order("updated_at desc").Scan(&recordInfo) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return nil, errors.New("根据jwcode查询提交记录失败") |
|
|
} |
|
|
} |
|
|
for i, title := range recordInfo { |
|
|
for i, title := range recordInfo { |
|
|
err = dao.ActivityInteractiveForm.Ctx(ctx).Fields("description", "type").Where("id", title.FormId).Scan(&recordInfo[i]) |
|
|
err = dao.ActivityInteractiveForm.Ctx(ctx).Fields("description", "type").Where("id", title.FormId).Scan(&recordInfo[i]) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return nil, errors.New("根据jwcode查询作业题目信息失败") |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
record[i].Reply = recordInfo |
|
|
record[i].Reply = recordInfo |
|
@ -135,13 +137,49 @@ func (s *sRecord) GetRecordByCondition(ctx context.Context, groupId, jwcode int, |
|
|
|
|
|
|
|
|
// 查询部门信息
|
|
|
// 查询部门信息
|
|
|
func (s *sRecord) GetDeptInfo(ctx context.Context) (depts []pkgRecord.GetDeptInfoRes, err error) { |
|
|
func (s *sRecord) GetDeptInfo(ctx context.Context) (depts []pkgRecord.GetDeptInfoRes, err error) { |
|
|
|
|
|
// 从Redis中获取数据
|
|
|
|
|
|
value, _ := g.Redis().Get(ctx, "deptinfo") |
|
|
|
|
|
if value.String() != "" { |
|
|
|
|
|
err = json.Unmarshal(value.Bytes(), &depts) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("从Redis获取数据,JSON解析失败") |
|
|
|
|
|
} |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果Redis中没有数据,查询数据库
|
|
|
err = g.DB("cms").Model("member_info").Fields("deptId", "deptName").Group("deptId").Scan(&depts) |
|
|
err = g.DB("cms").Model("member_info").Fields("deptId", "deptName").Group("deptId").Scan(&depts) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("查询部门信息失败") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 将查询结果JSON化并存入Redis
|
|
|
|
|
|
deptJSON, _ := json.Marshal(depts) |
|
|
|
|
|
_, err = g.Redis().Set(ctx, "deptinfo", deptJSON) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("Redis存储失败") |
|
|
|
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 根据部门信息查询门店信息
|
|
|
// 根据部门信息查询门店信息
|
|
|
func (s *sRecord) GetShopInfoByDeptId(ctx context.Context, deptId string) (shops []pkgRecord.GetShopInfoByDeptIdRes, err error) { |
|
|
func (s *sRecord) GetShopInfoByDeptId(ctx context.Context, deptId string) (shops []pkgRecord.GetShopInfoByDeptIdRes, err error) { |
|
|
|
|
|
// 从Redis中获取数据
|
|
|
|
|
|
value, _ := g.Redis().Get(ctx, fmt.Sprintf("%s shopinfo", deptId)) |
|
|
|
|
|
if value.String() != "" { |
|
|
|
|
|
err = json.Unmarshal(value.Bytes(), &shops) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("从Redis获取数据,JSON解析失败") |
|
|
|
|
|
} |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果Redis中没有数据,查询数据库
|
|
|
err = g.DB("cms").Model("member_info").Fields("shopId", "shopName"). |
|
|
err = g.DB("cms").Model("member_info").Fields("shopId", "shopName"). |
|
|
Where("deptId", deptId).Group("shopId").Scan(&shops) |
|
|
Where("deptId", deptId).Group("shopId").Scan(&shops) |
|
|
|
|
|
|
|
|
|
|
|
// 将查询结果JSON化并存入Redis
|
|
|
|
|
|
shopJSON, _ := json.Marshal(shops) |
|
|
|
|
|
_, err = g.Redis().Set(ctx, fmt.Sprintf("%s shopinfo", deptId), shopJSON) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |