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

接口规范

parent 678e2873
...@@ -10,6 +10,7 @@ import cn.breeze.elleai.domain.sparring.service.ExamineService; ...@@ -10,6 +10,7 @@ import cn.breeze.elleai.domain.sparring.service.ExamineService;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import io.micrometer.common.util.StringUtils; import io.micrometer.common.util.StringUtils;
...@@ -22,10 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -22,10 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -43,7 +41,7 @@ public class AppExamineService { ...@@ -43,7 +41,7 @@ public class AppExamineService {
private static String EXAM_REDIS_QUESTION_KEY = "EXAM_MASTER_QUESTION:%s:%s"; private static String EXAM_REDIS_QUESTION_KEY = "EXAM_MASTER_QUESTION:%s:%s";
private static String EXAM_REDIS_SESSION_KEY = "EXAM_MASTER_SESSION:%d:%s"; private static String EXAM_REDIS_SESSION_KEY = "EXAM_MASTER_SESSION:%d:%d:%s";
private static String EXAM_REDIS_CAS_KEY = "EXAM_MASTER_CURRENT_AI_SCORE:%d:%s"; private static String EXAM_REDIS_CAS_KEY = "EXAM_MASTER_CURRENT_AI_SCORE:%d:%s";
...@@ -923,10 +921,32 @@ public class AppExamineService { ...@@ -923,10 +921,32 @@ public class AppExamineService {
} }
public ApiResponse<ExamineQaDifyDto> getQuestion(Integer tenant, Integer examineId, String sessionId, String userId) { /**
* 开始考试,获取出题
* @param examineId
* @param userId
* @param examineMode
* @return
*/
public ExamineQaDifyDto getQuestion(Integer examineId, String userId, Integer examineMode) {
// 获取缓存考试会话信息
String examSessionKey = String.format(EXAM_REDIS_SESSION_KEY, examineId, examineMode, userId);
String sessionId = redisTemplate.opsForValue().get(examSessionKey);
if(StrUtil.isEmptyIfStr(sessionId)) {
// 生成sessionId
sessionId = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(examSessionKey, sessionId, 1, TimeUnit.DAYS);
}
// 获取缓存考题信息
String questionKey = String.format(EXAM_REDIS_QUESTION_KEY, examineId, examineMode, userId, sessionId);
ExamineQaDifyDto result = new ExamineQaDifyDto(); ExamineQaDifyDto result = new ExamineQaDifyDto();
ExamineQaRequestModel req = null;
examineService.examineQaList(req);
// // 根据分类获取考题 // // 根据分类获取考题
// ExamineResponseModel model = examineService.examineDetail(examineId); // ExamineResponseModel model = examineService.examineDetail(examineId);
// if(Objects.nonNull(model)) { // if(Objects.nonNull(model)) {
...@@ -949,7 +969,7 @@ public class AppExamineService { ...@@ -949,7 +969,7 @@ public class AppExamineService {
// } // }
// } // }
return ApiResponse.ok(result); return result;
} }
} }
...@@ -58,5 +58,9 @@ public class ChatCompletionMobileController { ...@@ -58,5 +58,9 @@ public class ChatCompletionMobileController {
return ApiResponse.ok(aiReply); return ApiResponse.ok(aiReply);
} }
@Operation(summary = "开启新会话")
@PostMapping("/new")
public ApiResponse<String> newChatCompletion(@RequestParam("user_id") String userId) {
return ApiResponse.ok("ok");
}
} }
...@@ -11,6 +11,7 @@ import cn.breeze.elleai.application.dto.response.ExamineRecordDto; ...@@ -11,6 +11,7 @@ import cn.breeze.elleai.application.dto.response.ExamineRecordDto;
import cn.breeze.elleai.application.dto.response.ExamineRecordMobileDto; import cn.breeze.elleai.application.dto.response.ExamineRecordMobileDto;
import cn.breeze.elleai.application.service.AppExamineService; import cn.breeze.elleai.application.service.AppExamineService;
import cn.breeze.elleai.config.QueryParam; import cn.breeze.elleai.config.QueryParam;
import cn.breeze.elleai.util.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
...@@ -71,7 +72,7 @@ public class ExamineController { ...@@ -71,7 +72,7 @@ public class ExamineController {
@Operation(summary = "对练记录列表", tags = "对练记录") @Operation(summary = "对练记录列表", tags = "对练记录")
@GetMapping("/record/list") @GetMapping("/record/list")
public ApiResponse<PageResult<ExamineRecordDto>> recordList(@QueryParam ExamineRecordRequestDto request) { public ApiResponse<PageResult<ExamineRecordDto>> recordList(UserPrincipal userPrincipal, @QueryParam ExamineRecordRequestDto request) {
PageResult<ExamineRecordDto> pageResult = examineService.examineRecordPaginQuery(request); PageResult<ExamineRecordDto> pageResult = examineService.examineRecordPaginQuery(request);
return ApiResponse.ok(pageResult); return ApiResponse.ok(pageResult);
} }
......
...@@ -13,6 +13,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; ...@@ -13,6 +13,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.UUID;
@RestController @RestController
@RequestMapping(value = "/front/examine") @RequestMapping(value = "/front/examine")
@Tag(name = "AI对练移动端") @Tag(name = "AI对练移动端")
...@@ -87,33 +89,10 @@ public class ExamineMobileController { ...@@ -87,33 +89,10 @@ public class ExamineMobileController {
@Operation(summary = "开始考试,获取出题") @Operation(summary = "开始考试,获取出题")
@GetMapping(value = "/get_question") @GetMapping(value = "/get_question")
public ApiResponse<ExamineQaDifyDto> getQuestion(@Schema(description = "对练ID") @RequestParam("examine_id") Integer examineId, public ApiResponse<ExamineQaDifyDto> getQuestion(@Schema(description = "对练ID") @RequestParam("examine_id") Integer examineId,
@Schema(description = "会话ID") @RequestParam("session_id") String sessionId, @Schema(description = "对练模式(0练习 1对练)") @RequestParam("examine_mode") Integer examineMode,
@Schema(description = "用户ID") @RequestParam("user_id") String userId) { @Schema(description = "用户ID") @RequestParam("user_id") String userId) {
ExamineQaDifyDto result = new ExamineQaDifyDto(); ExamineQaDifyDto result = examineService.getQuestion(examineId, userId, examineMode);
// // 根据分类获取考题
// ElehKnowledgeTagDo tagDo = tagMapper.selectByCode(tenant, code);
// if(Objects.nonNull(tagDo)) {
// Long maxQuestionId = qaRecordMapper.selectSessionMaxQuestionId(tenant, sessionId, userId);
// maxQuestionId = Objects.nonNull(maxQuestionId) ? maxQuestionId : 0;
// ElehKnowledgeDo knowledgeDo = knowledgeMapper.selectQuestion(tenant, tagDo.getId(), maxQuestionId);
// if(Objects.nonNull(knowledgeDo)) {
// result.setQuestion(knowledgeDo.getQuestion());
// result.setAnswer(knowledgeDo.getAnswer());
// result.setProject(tagDo.getName());
// result.setCode(tagDo.getCode());
// result.setQuestionId(knowledgeDo.getId());
// result.setNext(true);
//
// // 存储当前会话考试信息
// String redisKey = String.format(EXAM_REDIS_QUESTION_KEY, tenant, sessionId, userId);
// redisTemplate.opsForValue().set(redisKey, result.getQuestionId()+"", 10, TimeUnit.MINUTES);
//
// log.info("出题结果:result = {}, rediskey = {}", JSONObject.toJSONString(result), redisKey);
// }
// }
return ApiResponse.ok(result); return ApiResponse.ok(result);
} }
......
package cn.breeze.elleai.controller;
import cn.breeze.elleai.application.dto.ApiResponse;
import cn.breeze.elleai.application.dto.response.ExamineSceneDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/front/user")
@Tag(name = "用户移动端")
@RequiredArgsConstructor
public class UserMobileController {
@Operation(summary = "获取token")
@GetMapping("/get_token")
public ApiResponse<String> getToken() {
return ApiResponse.ok("ok");
}
}
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