|
@ -71,72 +71,61 @@ func (s *sRecord) GetRecordList(ctx context.Context, groupId, pageNo, pageSize i |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 根据条件查询 对所有结果进行筛选
|
|
|
|
|
|
|
|
|
// 查询作业提交明细,包含条件查询
|
|
|
func (s *sRecord) GetRecordByCondition(ctx context.Context, groupId, jwcode int, deptId, shopId string, pageNo, pageSize int) (record []pkgRecord.GetRecordListRes, err error) { |
|
|
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 recordList, err |
|
|
|
|
|
} |
|
|
|
|
|
//判断传来的jwcode, deptId, shopId是否为空,根据情况进行不同的筛选
|
|
|
|
|
|
if jwcode == 0 { //没有传jwcode
|
|
|
|
|
|
if deptId == "" && shopId == "" { //000
|
|
|
|
|
|
return recordList, err |
|
|
|
|
|
} 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) |
|
|
|
|
|
|
|
|
query := dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode") |
|
|
|
|
|
|
|
|
|
|
|
//增加条件筛选
|
|
|
|
|
|
if jwcode != 0 { |
|
|
|
|
|
query = query.Where("jwcode", jwcode) |
|
|
} |
|
|
} |
|
|
|
|
|
if deptId != "" { |
|
|
|
|
|
query = query.Where("deptId", deptId) |
|
|
} |
|
|
} |
|
|
if record == nil { |
|
|
|
|
|
return nil, errors.New("只精网号没有查询到相关记录") |
|
|
|
|
|
|
|
|
if shopId != "" { |
|
|
|
|
|
query = query.Where("shopId", shopId) |
|
|
} |
|
|
} |
|
|
return record, err |
|
|
|
|
|
} else if deptId != "" && shopId == "" { //110
|
|
|
|
|
|
for _, info := range recordList { |
|
|
|
|
|
if info.Jwcode == jwcode && info.DeptId == deptId { |
|
|
|
|
|
record = append(record, info) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//分页处理
|
|
|
|
|
|
if pageNo > 0 && pageSize > 0 { |
|
|
|
|
|
query = query.Page(pageNo, pageSize) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = query.Scan(&record) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("查询作业提交明细中jwcode失败") |
|
|
} |
|
|
} |
|
|
if record == nil { |
|
|
|
|
|
return nil, errors.New("精网号,部门 没有查询到相关记录") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//补充详细信息逻辑:根据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 { |
|
|
|
|
|
return nil, errors.New("无条件根据jwcode查member_info表失败") |
|
|
} |
|
|
} |
|
|
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) |
|
|
|
|
|
|
|
|
total, err1 := dao.ActivityInteractiveRecord.Ctx(ctx).Fields("jwcode").Where("group_id", groupId).Group("jwcode").Count() |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
return nil, errors.New("无条件查询总数失败") |
|
|
} |
|
|
} |
|
|
|
|
|
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) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("根据jwcode查询提交记录失败") |
|
|
} |
|
|
} |
|
|
if record == nil { |
|
|
|
|
|
return nil, errors.New("精网号,部门,门店 没有查询到相关记录") |
|
|
|
|
|
|
|
|
for i, title := range recordInfo { |
|
|
|
|
|
err = dao.ActivityInteractiveForm.Ctx(ctx).Fields("description", "type").Where("id", title.FormId).Scan(&recordInfo[i]) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, errors.New("根据jwcode查询作业题目信息失败") |
|
|
} |
|
|
} |
|
|
return record, err |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
record[i].Reply = recordInfo |
|
|
|
|
|
//fmt.Println(record)
|
|
|
} |
|
|
} |
|
|
return nil, errors.New("检查一下穿的参数是否正常") |
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 查询部门信息
|
|
|
// 查询部门信息
|
|
|