Commit 5d0fa2fb authored by 陈立彬's avatar 陈立彬

考试评分异步流程

parent a04704a8
...@@ -46,7 +46,9 @@ public class ExamController { ...@@ -46,7 +46,9 @@ public class ExamController {
private final ExamAppFacade examAppFacade; private final ExamAppFacade examAppFacade;
private static String EXAM_REDIS_SESSION_KEY = "EXAM_MASTER:%d:%s:%s"; private static String EXAM_REDIS_QUESTION_KEY = "EXAM_MASTER_QUESTION:%d:%s:%s";
private static String EXAM_REDIS_SESSION_KEY = "EXAM_MASTER_SESSION:%d:%s:%s";
@GetMapping(value = "/list") @GetMapping(value = "/list")
public String list() { public String list() {
...@@ -63,7 +65,7 @@ public class ExamController { ...@@ -63,7 +65,7 @@ public class ExamController {
GetQuestionResponseResult result = new GetQuestionResponseResult(); GetQuestionResponseResult result = new GetQuestionResponseResult();
String redisKey = String.format(EXAM_REDIS_SESSION_KEY, tenant, sessionId, userId); String redisKey = String.format(EXAM_REDIS_QUESTION_KEY, tenant, sessionId, userId);
String currentQuestion = redisTemplate.opsForValue().get(redisKey); String currentQuestion = redisTemplate.opsForValue().get(redisKey);
...@@ -108,7 +110,7 @@ public class ExamController { ...@@ -108,7 +110,7 @@ public class ExamController {
result.setNext(true); result.setNext(true);
// 存储当前会话考试信息 // 存储当前会话考试信息
String redisKey = String.format(EXAM_REDIS_SESSION_KEY, tenant, sessionId, userId); String redisKey = String.format(EXAM_REDIS_QUESTION_KEY, tenant, sessionId, userId);
redisTemplate.opsForValue().set(redisKey, result.getQuestionId()+"", 10, TimeUnit.MINUTES); redisTemplate.opsForValue().set(redisKey, result.getQuestionId()+"", 10, TimeUnit.MINUTES);
log.info("出题结果:result = {}, rediskey = {}", JSONObject.toJSONString(result), redisKey); log.info("出题结果:result = {}, rediskey = {}", JSONObject.toJSONString(result), redisKey);
...@@ -216,7 +218,8 @@ public class ExamController { ...@@ -216,7 +218,8 @@ public class ExamController {
@PostMapping(value = "/run4score") @PostMapping(value = "/run4score")
public ApiResponse<String> run4Score(@RequestParam(value = "scene") String scene, public ApiResponse<String> run4Score(@RequestParam(value = "tenant") Integer tenant,
@RequestParam(value = "scene") String scene,
@RequestParam(value = "session_id") String sessionId, @RequestParam(value = "session_id") String sessionId,
@RequestParam(value = "user_id") String userId, @RequestParam(value = "user_id") String userId,
@RequestParam(value = "question") String question, @RequestParam(value = "question") String question,
...@@ -224,8 +227,35 @@ public class ExamController { ...@@ -224,8 +227,35 @@ public class ExamController {
@RequestParam(value = "user_answer") String userAnswer) { @RequestParam(value = "user_answer") String userAnswer) {
String redisKey = String.format(EXAM_REDIS_SESSION_KEY, tenant, sessionId, userId);
SingleQaResult qa = new SingleQaResult();
qa.setUserId(userId);
qa.setSessionId(sessionId);
qa.setUserAnswer(userAnswer);
qa.setQuestion(question);
qa.setAnswer(answer);
qa.setScene(scene);
redisTemplate.opsForValue().set(redisKey, JSONObject.toJSONString(qa), 30, TimeUnit.MINUTES);
examAppFacade.run4Score(scene, sessionId, userId, question, answer, userAnswer); examAppFacade.run4Score(scene, sessionId, userId, question, answer, userAnswer);
return ApiResponse.ok("ok"); return ApiResponse.ok("ok");
} }
@GetMapping(value = "/get_run4score_info")
public ApiResponse<SingleQaResult> getRun4ScoreInfo(@RequestParam(value = "tenant") Integer tenant,
@RequestParam(value = "session_id") String sessionId,
@RequestParam(value = "user_id") String userId) {
String redisKey = String.format(EXAM_REDIS_SESSION_KEY, tenant, sessionId, userId);
String redisValue = redisTemplate.opsForValue().get(redisKey);
if(StringUtils.isNotEmpty(redisValue)) {
return ApiResponse.ok(JSONObject.parseObject(redisValue, SingleQaResult.class));
}
return ApiResponse.fail("no cache data.");
}
} }
...@@ -22,4 +22,13 @@ public class SingleQaResult implements Serializable { ...@@ -22,4 +22,13 @@ public class SingleQaResult implements Serializable {
@JsonProperty("score_criteria") @JsonProperty("score_criteria")
private String scoreCriteria; private String scoreCriteria;
@JsonProperty("session_id")
private String sessionId;
@JsonProperty("user_id")
private String userId;
@JsonProperty("scene")
private String scene;
} }
...@@ -38,11 +38,13 @@ public class ExamAppFacade { ...@@ -38,11 +38,13 @@ public class ExamAppFacade {
param.put("query", userAnswer); param.put("query", userAnswer);
param.put("inputs", inputs); param.put("inputs", inputs);
param.put("response_mode", "blocking"); param.put("response_mode", "blocking");
param.put("conversation_id", sessionId); param.put("conversation_id", "");
param.put("user", userId); param.put("user", userId);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(apiKey); headers.setBearerAuth(apiKey);
log.info("异步请求参数,req = {}", JSONObject.toJSONString(param));
HttpEntity<String> postEntity = new HttpEntity<>(param.toJSONString(), headers); HttpEntity<String> postEntity = new HttpEntity<>(param.toJSONString(), headers);
ResponseEntity<String> response = restTemplate.postForEntity(difyBase + "/chat-messages", postEntity, String.class); ResponseEntity<String> response = restTemplate.postForEntity(difyBase + "/chat-messages", postEntity, String.class);
log.info("执行结果:", JSONObject.parseObject(response.getBody())); log.info("执行结果:", JSONObject.parseObject(response.getBody()));
......
...@@ -96,4 +96,8 @@ minio-file: ...@@ -96,4 +96,8 @@ minio-file:
domain-prefix: http://files.hc.wxpai.cn/ domain-prefix: http://files.hc.wxpai.cn/
intercept-prefix: http://minio:9000/ intercept-prefix: http://minio:9000/
upload-prefix: upload upload-prefix: upload
download-url-prefix: http://minio:9000/ download-url-prefix: http://minio:9000/
\ No newline at end of file
dify:
api_base: http://dify-api-ga.tech:5001/v1
api_key: app-yaoa2lAMGJzB11ZGxd5P4iTQ
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment