文章目录
- 1.分页查询面试记录
- 1.req和vo
- 1.InterviewHistoryReq.java
- 2.InterviewHistoryVO.java
- 2.InterviewController.java
- 3.service
- 1.InterviewHistoryService.java
- 2.InterviewHistoryServiceImpl.java
- 4.测试
- 2.查询面试详情
- 1.InterviewQuestionHistoryVO.java
- 2.InterviewController.java
- 3.InterviewQuestionHistoryService.java
- 4.InterviewQuestionHistoryServiceImpl.java
- 5.测试
1.分页查询面试记录
1.req和vo
1.InterviewHistoryReq.java
package com.sunxiansheng.interview.server.entity.req;
import com.sunxiansheng.interview.server.entity.page.PageInfo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class InterviewHistoryReq implements Serializable {
private static final long serialVersionUID = 1L;
private PageInfo pageInfo;
}
2.InterviewHistoryVO.java
package com.sunxiansheng.interview.api.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class InterviewHistoryVO implements Serializable {
private static final long serialVersionUID = -69404155056273562L;
private Long id;
private double avgScore;
private String keyWords;
private String tip;
private Long createdTime;
}
2.InterviewController.java
@PostMapping(value = "/getHistory")
public Result<PageResult<InterviewHistoryVO>> getHistory(@RequestBody InterviewHistoryReq req) {
try {
if (log.isInfoEnabled()) {
log.info("分页查询面试记录入参{}", JSON.toJSONString(req));
}
Preconditions.checkArgument(!Objects.isNull(req), "参数不能为空!");
PageResult<InterviewHistoryVO> result = interviewHistoryService.getHistory(req);
if (log.isInfoEnabled()) {
log.info("分页查询面试记录出参{}", JSON.toJSONString(result));
}
return Result.ok(result);
} catch (IllegalArgumentException e) {
log.error("参数异常!错误原因{}", e.getMessage(), e);
return Result.fail(e.getMessage());
} catch (Exception e) {
log.error("分页查询面试记录异常!错误原因{}", e.getMessage(), e);
return Result.fail("分页查询面试记录异常!");
}
}
3.service
1.InterviewHistoryService.java
PageResult<InterviewHistoryVO> getHistory(InterviewHistoryReq req);
2.InterviewHistoryServiceImpl.java
@Override
public PageResult<InterviewHistoryVO> getHistory(InterviewHistoryReq req) {
InterviewHistoryPo interviewHistoryPo = new InterviewHistoryPo();
interviewHistoryPo.setCreatedBy(LoginUtil.getLoginId());
Integer pageNo = req.getPageInfo().getPageNo();
Integer pageSize = req.getPageInfo().getPageSize();
PageResult<InterviewHistoryPo> paginate = SunPageHelper.paginate(pageNo, pageSize,
() -> this.interviewHistoryMapper.count(interviewHistoryPo),
(offset, limit) -> this.interviewHistoryMapper.queryPage(interviewHistoryPo, offset, limit));
List<InterviewHistoryPo> result = paginate.getResult();
List<InterviewHistoryVO> collect = result.stream().map(
res -> {
InterviewHistoryVO interviewHistoryVO = new InterviewHistoryVO();
interviewHistoryVO.setId(res.getId());
interviewHistoryVO.setAvgScore(res.getAvgScore());
interviewHistoryVO.setKeyWords(res.getKeyWords());
interviewHistoryVO.setTip(res.getTip());
interviewHistoryVO.setCreatedTime(res.getCreatedTime().getTime());
return interviewHistoryVO;
}
).collect(Collectors.toList());
PageResult<InterviewHistoryVO> build = new PageResult.Builder<InterviewHistoryVO>()
.pageNo(pageNo)
.pageSize(pageSize)
.total(paginate.getTotal())
.result(collect)
.build();
return build;
}
4.测试
2.查询面试详情
1.InterviewQuestionHistoryVO.java
package com.sunxiansheng.interview.api.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class InterviewQuestionHistoryVO implements Serializable {
private static final long serialVersionUID = -60560874889446691L;
private Double score;
private String keyWords;
private String question;
private String answer;
private String userAnswer;
}
2.InterviewController.java
@GetMapping(value = "/detail")
public Result<List<InterviewQuestionHistoryVO>> detail(Long id) {
try {
if (log.isInfoEnabled()) {
log.info("查询详情入参{}", id);
}
Preconditions.checkArgument(!Objects.isNull(id), "参数不能为空!");
List<InterviewQuestionHistoryVO> result = interviewQuestionHistoryService.detail(id);
if (log.isInfoEnabled()) {
log.info("查询详情出参{}", JSON.toJSONString(result));
}
return Result.ok(result);
} catch (IllegalArgumentException e) {
log.error("参数异常!错误原因{}", e.getMessage(), e);
return Result.fail(e.getMessage());
} catch (Exception e) {
log.error("查询详情异常!错误原因{}", e.getMessage(), e);
return Result.fail("查询详情异常!");
}
}
3.InterviewQuestionHistoryService.java
List<InterviewQuestionHistoryVO> detail(Long id);
4.InterviewQuestionHistoryServiceImpl.java
@Override
public List<InterviewQuestionHistoryVO> detail(Long id) {
InterviewQuestionHistoryPo interviewQuestionHistoryPo = new InterviewQuestionHistoryPo();
interviewQuestionHistoryPo.setInterviewId(id);
interviewQuestionHistoryPo.setCreatedBy(LoginUtil.getLoginId());
List<InterviewQuestionHistoryPo> interviewQuestionHistoryPoList = this.interviewQuestionHistoryMapper.queryAllByLimit(interviewQuestionHistoryPo);
List<InterviewQuestionHistoryVO> collect = interviewQuestionHistoryPoList.stream().map(
interviewQuestionHistoryPo1 -> {
InterviewQuestionHistoryVO interviewQuestionHistoryVO = new InterviewQuestionHistoryVO();
interviewQuestionHistoryVO.setScore(interviewQuestionHistoryPo1.getScore());
interviewQuestionHistoryVO.setKeyWords(interviewQuestionHistoryPo1.getKeyWords());
interviewQuestionHistoryVO.setQuestion(interviewQuestionHistoryPo1.getQuestion());
interviewQuestionHistoryVO.setAnswer(interviewQuestionHistoryPo1.getAnswer());
interviewQuestionHistoryVO.setUserAnswer(interviewQuestionHistoryPo1.getUserAnswer());
return interviewQuestionHistoryVO;
}
).collect(Collectors.toList());
return collect;
}
5.测试