分页查询面试记录和面试详情

文章目录

1.分页查询面试记录

1.req和vo
1.InterviewHistoryReq.java
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;

/**
 * 分页信息
 *
 * @author sun
 * @since 2024-07-21 16:03:41
 */
@Data
@Accessors(chain = true) // 支持链式调用
public class InterviewHistoryReq implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 分页信息
     */
    private PageInfo pageInfo;

}
2.InterviewHistoryVO.java
java 复制代码
package com.sunxiansheng.interview.api.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * 面试汇总记录表(InterviewHistory)实体类
 *
 * @author makejava
 * @since 2024-05-23 22:56:03
 */
@Data
public class InterviewHistoryVO implements Serializable {
    private static final long serialVersionUID = -69404155056273562L;
    /**
     * id
     */
    private Long id;
    /**
     * 平均分
     */
    private double avgScore;
    /**
     * 面试关键字
     */
    private String keyWords;
    /**
     * 面试评价
     */
    private String tip;
    /**
     * 创建时间
     */
    private Long createdTime;

}
2.InterviewController.java
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
java 复制代码
    PageResult<InterviewHistoryVO> getHistory(InterviewHistoryReq req);
2.InterviewHistoryServiceImpl.java
java 复制代码
    /**
     * 分页查询
     *
     * @param req
     * @return
     */
    @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
java 复制代码
package com.sunxiansheng.interview.api.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * 面试题目记录表(InterviewQuestionHistory)实体类
 *
 * @author makejava
 * @since 2024-05-23 22:56:31
 */
@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
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
java 复制代码
    /**
     * 详情
     * @param id
     * @return
     */
    List<InterviewQuestionHistoryVO> detail(Long id);
4.InterviewQuestionHistoryServiceImpl.java
java 复制代码
    /**
     * 详情
     * @param id
     * @return
     */
    @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.测试
相关推荐
岁岁岁平安24 天前
JavaWeb实战(1)(重点:分页查询、jstl标签与jsp、EL表达式、Bootstrap组件搭建页面、jdbc)
java·servlet·javaweb·jsp·el·分页查询·jstl
zzzzzzzz'4 个月前
个人旅游网(3)——功能详解——旅游路线功能
web·旅游·分页查询·模糊搜索
码农研究僧7 个月前
详细分析Mybatis与MybatisPlus中分页查询的差异(附Demo)
xml·java·mybatis·mybatisplus·分页查询
失舵之舟-9 个月前
【Mysql数据库基础05】子查询 where、from、exists子查询、分页查询
数据库·mysql·子查询·数据库系统·分页查询·where子查询·from子查询
啊Q老师1 年前
MyBatis:Generator
mybatis·存储过程·generator·批量操作·分页查询
赵延东的一亩三分地1 年前
【SQL开发实战技巧】系列(二十二):数仓报表场景☞ 从分析函数效率一定快吗聊一聊结果集分页和隔行抽样实现方式
数据仓库·分页查询·随机抽样·分析函数优化·merge调优