5 changed files with 144 additions and 6 deletions
@ -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); |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
@ -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) ; |
||||
|
||||
} |
@ -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…
Reference in new issue