|
@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
@@ -115,6 +116,8 @@ public class CmsAccountController {
|
|
|
|
|
|
|
|
private final ChatGptAccountService chatGptAccountService;
|
|
private final ChatGptAccountService chatGptAccountService;
|
|
|
|
|
|
|
|
|
|
+ private final ChatgptSessionMapper chatgptSessionMapper;
|
|
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
|
@GetMapping("/get")
|
|
@GetMapping("/get")
|
|
@@ -1256,4 +1259,74 @@ public class CmsAccountController {
|
|
|
.build());
|
|
.build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取镜像车队账号列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/mirror/car/session")
|
|
|
|
|
+ public Result<SearchResult<ChatgptCarSessionView>> getMirrorCarSession() {
|
|
|
|
|
+ SearchResult<ChatgptCarSessionView> search = beanSearcher.search(ChatgptCarSessionView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
|
|
+ .orderBy(ChatgptCarSessionView::getId).desc()
|
|
|
|
|
+ .build());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 编辑镜像车队账号列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping("/update/mirror/car/session")
|
|
|
|
|
+ public Result<String> updateMirrorCarSession(@RequestBody ChatgptSession chatgptSession) {
|
|
|
|
|
+ Long id = chatgptSession.getId();
|
|
|
|
|
+ ChatgptSession dbChatSession = chatgptSessionMapper.selectById(id);
|
|
|
|
|
+ if (!ObjectUtil.equal(dbChatSession.getEmail(), chatgptSession.getEmail()) || !ObjectUtil.equal(dbChatSession.getPassword(), chatgptSession.getPassword())) {
|
|
|
|
|
+ String gptSession = chatGptAccountService.getGptSession(dbChatSession.getEmail(), dbChatSession.getPassword());
|
|
|
|
|
+ dbChatSession.setOfficialSession(gptSession);
|
|
|
|
|
+ dbChatSession.setEmail(chatgptSession.getEmail());
|
|
|
|
|
+ dbChatSession.setPassword(chatgptSession.getPassword());
|
|
|
|
|
+ }
|
|
|
|
|
+ chatgptSessionMapper.updateById(dbChatSession);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除镜像车队账号
|
|
|
|
|
+ */
|
|
|
|
|
+ @DeleteMapping("/delete/mirror/car/session/{id}")
|
|
|
|
|
+ public Result<String> deleteMirrorCarSession(@PathVariable Long id) {
|
|
|
|
|
+ Optional.ofNullable(chatgptSessionMapper.selectById(id))
|
|
|
|
|
+ .ifPresent(e -> {
|
|
|
|
|
+ String carId = e.getCarId();
|
|
|
|
|
+ if (StrUtil.isNotBlank(carId)) {
|
|
|
|
|
+ chatgptSessionMapper.deleteById(e.getId());
|
|
|
|
|
+
|
|
|
|
|
+ String carConversationKey = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carId;
|
|
|
|
|
+ String highCarChatKey = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
|
|
|
|
|
+ String lowCarChatKey = RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId;
|
|
|
|
|
+ //从zSet中删除车队
|
|
|
|
|
+ String carScoresKey = RedisService.key.CHATGPT_CAR_SCORES.getName();
|
|
|
|
|
+ redisService.zRemove(carScoresKey, carId);
|
|
|
|
|
+ redisService.del(highCarChatKey);
|
|
|
|
|
+ redisService.del(lowCarChatKey);
|
|
|
|
|
+ redisService.del(carConversationKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增镜像车队账号
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/post/mirror/car/session")
|
|
|
|
|
+ public Result<String> postMirrorCarSession(@RequestBody ChatgptSession chatgptSession) {
|
|
|
|
|
+ Integer selectCount = chatgptSessionMapper.selectCount(Wrappers.lambdaQuery(ChatgptSession.class)
|
|
|
|
|
+ .eq(ChatgptSession::getCarId, chatgptSession.getCarId()));
|
|
|
|
|
+ if (selectCount > 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("输入的车队id已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ String gptSession = chatGptAccountService.getGptSession(chatgptSession.getEmail(), chatgptSession.getPassword());
|
|
|
|
|
+ chatgptSession.setIsCar(true);
|
|
|
|
|
+ chatgptSession.setOfficialSession(gptSession);
|
|
|
|
|
+ chatgptSessionMapper.insert(chatgptSession);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|