diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java index df017eb..0b356e0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java @@ -220,14 +220,16 @@ public class AuthController { @PostMapping("/social-login-openid") @PermitAll @Operation(summary = "社交快捷登录,使用 code 授权码", description = "适合未登录的用户,但是社交账号已绑定用户") - public void socialQuickLoginOpenId(@RequestBody AuthSocialLoginReqVO reqVO) { + public CommonResult socialQuickLoginOpenId(@RequestBody AuthSocialLoginReqVO reqVO) { OAuth2AccessTokenDO accessToken = oAuth2TokenService.getAccessToken(reqVO.getOpenid()); Long userId = accessToken.getUserId(); List socialUserList = socialUserService.getSocialUserList(userId, UserTypeEnum.MEMBER.getValue()); //判断是否为对象空 - if(!CollUtil.isEmpty(socialUserList)){ + if(!CollUtil.isEmpty(socialUserList) && StrUtil.isNotEmpty(reqVO.getCode())){ stringRedisTemplate.opsForValue().set(reqVO.getCode(), JsonUtils.toJsonString(socialUserList.get(0)),10, TimeUnit.MINUTES); + return success(true); } + return success(false); } @PostMapping("/social-qr-login-openid") @@ -244,11 +246,14 @@ public class AuthController { authSocialLoginReqVO.setType(socialUserDO.getType()); authSocialLoginReqVO.setState(socialUserDO.getState()); authSocialLoginReqVO.setOpenid(socialUserDO.getOpenid()); - return success(authService.socialLogin(authSocialLoginReqVO)); - } - else{ - return success(null); + AuthLoginRespVO authLoginRespVO = authService.socialLogin(authSocialLoginReqVO); + if(ObjUtil.isNotEmpty(authLoginRespVO)){ + stringRedisTemplate.delete(reqVO.getCode()); + return success(authLoginRespVO); + } + } + return success(null); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/MaxkbController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/MaxkbController.java new file mode 100644 index 0000000..46ed0fd --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/MaxkbController.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.system.controller.admin.maxkb; + +import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import cn.iocoder.yudao.module.system.service.maxkb.MaxkbApiService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; + +@Tag(name = "管理后台 - maxkb") +@RestController +@RequestMapping("/system/maxkb") +@Validated +@Slf4j +public class MaxkbController { + @Resource + MaxkbApiService maxkbApiService; + + @PostMapping("/pushWeb") + @PermitAll + @Operation(summary = "导入知识库") + public void pushWebUrl(MaxkbdocumentVo maxkbdocumentVo) { + maxkbApiService.pushWebUrl(maxkbdocumentVo); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/vo/MaxkbdocumentVo.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/vo/MaxkbdocumentVo.java new file mode 100644 index 0000000..dbbf3d7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/vo/MaxkbdocumentVo.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.system.controller.admin.maxkb.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.util.List; + +@Data +public class MaxkbdocumentVo { + public String[] source_url_list; + public String selector; + @JsonIgnore + public String id; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java new file mode 100644 index 0000000..24220b7 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.module.system.service.maxkb; + +import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; + +import java.util.List; + +public interface MaxkbApiService { + + public void getAccessToken() ; + + public void pushWebUrl(MaxkbdocumentVo maxkbdocumentVo) ; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java new file mode 100644 index 0000000..94cd3c9 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.module.system.service.maxkb; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.framework.common.util.http.HttpUtils; +import cn.iocoder.yudao.module.infra.api.config.ConfigApi; +import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +@Service +@Slf4j +public class MaxkbApiServiceImpl implements MaxkbApiService { + + + static final String MAXKB_ACCOUNT_URL = "maxkb-account-url"; + static final String MAXKB_ACCOUNT_USER = "maxkb-account-user"; + static final String MAXKB_ACCOUNT_PASSWORD = "maxkb-account-password"; + + static final String MAXKB_ACCOUNT_TOKEN = "maxkb-account-url-token"; + + @Resource + private StringRedisTemplate stringRedisTemplate; + + @Resource + private ConfigApi configApi; + @Override + public void getAccessToken() { + String accountUrl = configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL); + String accountUser = configApi.getConfigValueByKey(MAXKB_ACCOUNT_USER); + String accountPassword = configApi.getConfigValueByKey(MAXKB_ACCOUNT_PASSWORD); + JSONObject jsonObject=new JSONObject(); + jsonObject.set("username",accountUser); + jsonObject.set("password",accountPassword); + String s = HttpUtils.post(accountUrl+"/api/user/login", null,jsonObject.toString()); + if(s!=null){ + JSONObject res = new JSONObject(s); + stringRedisTemplate.opsForValue().set(MAXKB_ACCOUNT_TOKEN, res.getStr("data"),10, TimeUnit.MINUTES); + } + } + + @Override + public void pushWebUrl(MaxkbdocumentVo maxkbdocumentVo) { + + String s = HttpUtils.post(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+maxkbdocumentVo.getId()+"/document/web",getMaxkbHeager(), JSONUtil.toJsonStr(maxkbdocumentVo)); + log.info("web知识库返回信息"+s); + } + + private MapgetMaxkbHeager(){ + String token = stringRedisTemplate.opsForValue().get(MAXKB_ACCOUNT_TOKEN); + if(StrUtil.isEmpty(token)){ + getAccessToken(); + token = stringRedisTemplate.opsForValue().get(MAXKB_ACCOUNT_TOKEN); + } + Map map=new HashMap<>(); + map.put("authorization",token); + map.put("content-type","application/json"); + return map; + } + + // /api/dataset/bff33a78-e5bd-11ef-825e-0242ac110003/document/web + +}