Browse Source

增加maxkb信息

master
赵鹏 2 months ago
parent
commit
f541779573
  1. 17
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
  2. 32
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/MaxkbController.java
  3. 16
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/maxkb/vo/MaxkbdocumentVo.java
  4. 13
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java
  5. 72
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java

17
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<Boolean> socialQuickLoginOpenId(@RequestBody AuthSocialLoginReqVO reqVO) {
OAuth2AccessTokenDO accessToken = oAuth2TokenService.getAccessToken(reqVO.getOpenid());
Long userId = accessToken.getUserId();
List<SocialUserDO> 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);
}

32
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);
}
}

16
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;
}

13
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) ;
}

72
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 Map<String,String>getMaxkbHeager(){
String token = stringRedisTemplate.opsForValue().get(MAXKB_ACCOUNT_TOKEN);
if(StrUtil.isEmpty(token)){
getAccessToken();
token = stringRedisTemplate.opsForValue().get(MAXKB_ACCOUNT_TOKEN);
}
Map<String,String> map=new HashMap<>();
map.put("authorization",token);
map.put("content-type","application/json");
return map;
}
// /api/dataset/bff33a78-e5bd-11ef-825e-0242ac110003/document/web
}
Loading…
Cancel
Save