文章目录
1.提交试卷 1.req和vo 1.InterviewSubmitReq.java 2.InterviewResultVO.java
2.InterviewController.java 3.service 1.InterviewHistoryService.java 2.InterviewHistoryServiceImpl.java 3.InterviewEngine.java 4.JiChiInterviewEngine.java 5.EvaluateUtils.java
4.测试
2.将信息存到history表中 1.InterviewHistoryService.java 2.InterviewHistoryServiceImpl.java 2.测试 1.apipost 2.debug 3.db 1.interview_history 2.interview_question_history
1.提交试卷
1.req和vo
1.InterviewSubmitReq.java
package com. sunxiansheng. interview. api. req ;
import com. sunxiansheng. interview. api. enums. EngineEnum ;
import lombok. Data ;
import lombok. Getter ;
import lombok. Setter ;
import java. io. Serializable ;
import java. util. List ;
@Getter
@Setter
public class InterviewSubmitReq implements Serializable {
private String engine = EngineEnum . JI_CHI . name ( ) ;
private String interviewUrl;
private List < Submit > questionList;
@Data
public static class Submit {
private String labelName;
private String subjectName;
private String subjectAnswer;
private String userAnswer;
private Double userScore;
}
}
2.InterviewResultVO.java
package com. sunxiansheng. interview. api. vo ;
import lombok. Getter ;
import lombok. Setter ;
import java. io. Serializable ;
@Getter
@Setter
public class InterviewResultVO implements Serializable {
private Double avgScore;
private String tips;
private String avgTips;
}
2.InterviewController.java
@PostMapping ( value = "/submit" )
public Result < InterviewResultVO > submit ( @RequestBody InterviewSubmitReq req) {
try {
if ( log. isInfoEnabled ( ) ) {
log. info ( "面试提交入参{}" , JSON . toJSON ( req) ) ;
}
Preconditions . checkArgument ( ! Objects . isNull ( req) , "参数不能为空!" ) ;
InterviewResultVO submit = interviewHistoryService. submit ( req) ;
return Result . ok ( submit) ;
} 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
InterviewResultVO submit ( InterviewSubmitReq req) ;
2.InterviewHistoryServiceImpl.java
@Override
public InterviewResultVO submit ( InterviewSubmitReq req) {
String engine = req. getEngine ( ) ;
InterviewEngine interviewEngine = engineMap. get ( engine) ;
Preconditions . checkArgument ( ! Objects . isNull ( interviewEngine) , "引擎不能为空!" ) ;
return interviewEngine. submit ( req) ;
}
3.InterviewEngine.java
InterviewResultVO submit ( InterviewSubmitReq req) ;
4.JiChiInterviewEngine.java
@Override
public InterviewResultVO submit ( InterviewSubmitReq req) {
InterviewResultVO interviewResultVO = new InterviewResultVO ( ) ;
List < InterviewSubmitReq. Submit > submits = req. getQuestionList ( ) ;
double total = submits. stream ( ) . mapToDouble ( InterviewSubmitReq. Submit :: getUserScore ) . sum ( ) ;
double avg = total / submits. size ( ) ;
interviewResultVO. setAvgScore ( avg) ;
String tips = submits. stream ( ) . map ( item -> {
String keyWord = item. getLabelName ( ) ;
String evaluate = EvaluateUtils . evaluate ( item. getUserScore ( ) ) ;
return String . format ( evaluate, keyWord) ;
} ) . distinct ( ) . collect ( Collectors . joining ( ";" ) ) ;
interviewResultVO. setTips ( tips) ;
String avgTips = EvaluateUtils . avgEvaluate ( avg) ;
interviewResultVO. setAvgTips ( avgTips) ;
return interviewResultVO;
}
5.EvaluateUtils.java
package com. sunxiansheng. interview. server. util ;
import lombok. AllArgsConstructor ;
import lombok. Data ;
import org. apache. commons. lang3. RandomUtils ;
import java. util. ArrayList ;
import java. util. List ;
import java. util. stream. Collectors ;
public class EvaluateUtils {
private static final List < Evaluate > evaluates = build ( ) ;
private static List < Evaluate > build ( ) {
List < Evaluate > list = new ArrayList < > ( ) ;
list. add ( new Evaluate ( 0 , 3 , "%s掌握较差,要加把劲" ) ) ;
list. add ( new Evaluate ( 0 , 3 , "%s掌握不大行,还要努努力" ) ) ;
list. add ( new Evaluate ( 0 , 3 , "%s掌握有点差,要加把劲" ) ) ;
list. add ( new Evaluate ( 0 , 3 , "%s掌握有点离谱,多想群友讨教讨教" ) ) ;
list. add ( new Evaluate ( 3 , 4 , "%s掌握还ok,努力再上一层楼" ) ) ;
list. add ( new Evaluate ( 3 , 4 , "%s掌握还不错,带飞下群友吧" ) ) ;
list. add ( new Evaluate ( 3 , 4 , "%s掌握好挺好的,分享下学习心得呗" ) ) ;
list. add ( new Evaluate ( 3 , 4 , "%s掌握的不赖,不能太飘" ) ) ;
list. add ( new Evaluate ( 4 , Integer . MAX_VALUE , "%s掌握的很好,以后就看你的了" ) ) ;
list. add ( new Evaluate ( 4 , Integer . MAX_VALUE , "%s掌握的很6,是个天才" ) ) ;
list. add ( new Evaluate ( 4 , Integer . MAX_VALUE , "%s掌握太熟了,未来可期" ) ) ;
list. add ( new Evaluate ( 4 , Integer . MAX_VALUE , "%s掌握太猛,不愧是顶级程序员" ) ) ;
return list;
}
@Data
@AllArgsConstructor
private static class Evaluate {
private double min;
private double max;
private String desc;
}
public static String avgEvaluate ( double score) {
if ( score >= 0 && score < 3 ) {
return "掌握较差" ;
} else if ( score >= 3 && score < 4 ) {
return "掌握程度 ok" ;
}
return "掌握程度很好" ;
}
public static String evaluate ( double score) {
List < Evaluate > list = evaluates. stream ( ) . filter ( item -> score >= item. getMin ( ) && score < item. getMax ( ) ) . collect ( Collectors . toList ( ) ) ;
return list. get ( RandomUtils . nextInt ( 0 , list. size ( ) ) ) . getDesc ( ) ;
}
}
4.测试
2.将信息存到history表中
1.InterviewHistoryService.java
void logInterview ( InterviewSubmitReq req, InterviewResultVO submit) ;
2.InterviewHistoryServiceImpl.java
@Override
@Transactional ( rollbackFor = Exception . class )
public void logInterview ( InterviewSubmitReq req, InterviewResultVO submit) {
Double avgScore = submit. getAvgScore ( ) ;
String avgTips = submit. getAvgTips ( ) ;
String interviewUrl = req. getInterviewUrl ( ) ;
List < Submit > questionList = req. getQuestionList ( ) ;
InterviewHistoryPo interviewHistoryPo = new InterviewHistoryPo ( ) ;
interviewHistoryPo. setAvgScore ( avgScore) ;
String keyWords = req. getQuestionList ( ) . stream ( ) . map ( InterviewSubmitReq. Submit :: getLabelName ) . distinct ( ) . collect ( Collectors . joining ( "、" ) ) ;
interviewHistoryPo. setKeyWords ( keyWords) ;
interviewHistoryPo. setTip ( avgTips) ;
interviewHistoryPo. setInterviewUrl ( interviewUrl) ;
interviewHistoryPo. setCreatedBy ( LoginUtil . getLoginId ( ) ) ;
interviewHistoryPo. setCreatedTime ( new Date ( ) ) ;
interviewHistoryPo. setIsDeleted ( 0 ) ;
this . interviewHistoryMapper. insert ( interviewHistoryPo) ;
List < InterviewQuestionHistoryPo > interviewQuestionHistoryPoList = questionList. stream ( ) . map (
question -> {
InterviewQuestionHistoryPo interviewQuestionHistoryPo = new InterviewQuestionHistoryPo ( ) ;
interviewQuestionHistoryPo. setInterviewId ( interviewHistoryPo. getId ( ) ) ;
interviewQuestionHistoryPo. setScore ( question. getUserScore ( ) ) ;
interviewQuestionHistoryPo. setKeyWords ( question. getLabelName ( ) ) ;
interviewQuestionHistoryPo. setQuestion ( question. getSubjectName ( ) ) ;
interviewQuestionHistoryPo. setAnswer ( question. getSubjectAnswer ( ) ) ;
interviewQuestionHistoryPo. setUserAnswer ( question. getUserAnswer ( ) ) ;
interviewQuestionHistoryPo. setCreatedBy ( LoginUtil . getLoginId ( ) ) ;
interviewQuestionHistoryPo. setCreatedTime ( new Date ( ) ) ;
interviewQuestionHistoryPo. setIsDeleted ( 0 ) ;
return interviewQuestionHistoryPo;
}
) . collect ( Collectors . toList ( ) ) ;
this . interviewQuestionHistoryMapper. insertBatch ( interviewQuestionHistoryPoList) ;
}
2.测试
1.apipost
2.debug
3.db
1.interview_history
2.interview_question_history