Explorar el Código

修改车队信息直接刷新

chenbiao hace 1 año
padre
commit
f4a21480ee

+ 23 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsGptCarController.java

@@ -6,21 +6,25 @@ import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
+import com.cyksj.common.util.StringUtil;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.ChatgptSessionMapper;
 import com.cyksj.model.dto.ChatGptChangePasswordDto;
 import com.cyksj.model.entity.ChatgptSession;
+import com.cyksj.model.entity.SysConfig;
 import com.cyksj.model.excel.ExcelGptMirrorAccountData;
 import com.cyksj.model.views.ChatgptCarSessionView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.mail.YhMailService;
+import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.web.util.EasyExcelUtils;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
@@ -58,6 +62,8 @@ public class CmsGptCarController {
 
 	private final YhMailService yhMailService;
 
+	private final SysConfigService sysConfigService;
+
 	/**
 	 * 获取镜像车队账号列表
 	 */
@@ -89,6 +95,7 @@ public class CmsGptCarController {
 		if (selectCount > 0) {
 			throw BusinessRuntimeException.getInstance("请检验车队ID或账号是否已存在");
 		}
+		refresh(chatgptSession.getId());
 		chatgptSessionMapper.updateById(chatgptSession);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
@@ -153,6 +160,7 @@ public class CmsGptCarController {
 			chatgptSession.setCarId("P" + chatgptSession.getId());
 			chatgptSession.setCarName("P" + chatgptSession.getId());
 		}
+		refresh(chatgptSession.getId());
 		chatgptSessionMapper.updateById(chatgptSession);
 
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
@@ -181,6 +189,7 @@ public class CmsGptCarController {
 		if (code == 1) {
 			//修改密码
 			chatgptSession.setPassword(chatGptChangePasswordDto.getPassword());
+			refresh(chatgptSession.getId());
 			chatgptSessionMapper.updateById(chatgptSession);
 			return GatewayResponse.SUCCESS.newBuilder().toResult();
 		} else {
@@ -198,6 +207,7 @@ public class CmsGptCarController {
 		if (dbChatSession != null) {
 			String gptSession = chatGptAccountService.getGptSession(dbChatSession.getEmail(), dbChatSession.getPassword());
 			dbChatSession.setOfficialSession(gptSession);
+			refresh(dbChatSession.getId());
 			chatgptSessionMapper.updateById(dbChatSession);
 		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
@@ -254,4 +264,17 @@ public class CmsGptCarController {
 		String linkUrl = yhMailService.readResetPwdResetLink(account);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(linkUrl);
 	}
+
+	private void refresh(Long id){
+		try {
+			SysConfig one = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_gpt_domain"));
+			List<String> array = new JSONArray(one.getSysValue()).toList(String.class);
+			array.forEach((domain)->{
+				String url = domain + "/backend-api/car/refresh?carId=" + id;
+				HttpUtil.get(url);
+			});
+		}catch (Exception e) {
+			log.error("刷新车队token异常:{}", StringUtil.getErrorText(e));
+		}
+	}
 }