|
|
@ -10,15 +10,25 @@ import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor; |
|
|
|
import com.aizuda.snailjob.client.job.core.dto.JobArgs; |
|
|
|
import com.aizuda.snailjob.client.model.ExecuteResult; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
|
|
import okhttp3.*; |
|
|
|
import okhttp3.RequestBody; |
|
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
|
import org.dromara.common.sse.dto.ChatGlmDto; |
|
|
|
import org.dromara.common.sse.listener.SSEListener; |
|
|
|
import org.dromara.common.sse.utils.ExecuteSSEUtil; |
|
|
|
import org.dromara.system.domain.vo.SysOssVo; |
|
|
|
import org.dromara.system.service.ISysOssService; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
@ -26,7 +36,7 @@ import org.springframework.validation.annotation.Validated; |
|
|
|
import org.dromara.common.web.core.BaseController; |
|
|
|
import org.dromara.common.core.domain.R; |
|
|
|
|
|
|
|
import org.dromara.productManagement.service.IPmgSupplierInformationService; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
@ -41,6 +51,11 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
@RestController |
|
|
|
@RequestMapping("/productManagement/supplierInformation") |
|
|
|
public class Qwen72bController extends BaseController { |
|
|
|
@Value("${chat.filePath}") |
|
|
|
private String chatFilePath; |
|
|
|
@Value("${chat.chatUrl}") |
|
|
|
private String chatUrl; |
|
|
|
private final ISysOssService ossService; |
|
|
|
|
|
|
|
private final OkHttpClient client = new OkHttpClient.Builder() |
|
|
|
.connectTimeout(300, TimeUnit.SECONDS)//连接超时(单位:秒)
|
|
|
@ -52,30 +67,8 @@ public class Qwen72bController extends BaseController { |
|
|
|
@SaCheckPermission("productManagement:supplierInformation:list") |
|
|
|
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
|
|
|
public R<String> list111(@RequestPart("file") MultipartFile file,String content) throws IOException, ExecutionException, InterruptedException { |
|
|
|
String destDir = "D:\\python项目39"; |
|
|
|
System.out.println(content); |
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
if (originalFilename == null) { |
|
|
|
throw new IllegalArgumentException("文件名不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取文件的后缀
|
|
|
|
String suffix = FileUtil.getSuffix(originalFilename); |
|
|
|
|
|
|
|
// 生成唯一的文件名
|
|
|
|
String name = IdUtil.fastSimpleUUID() + "." + suffix; |
|
|
|
|
|
|
|
// 构建目标文件路径
|
|
|
|
String destPath = destDir + File.separator + name; |
|
|
|
|
|
|
|
// 创建目标文件
|
|
|
|
File destFile = new File(destPath); |
|
|
|
FileUtil.writeFromStream(file.getInputStream(), destFile); |
|
|
|
if(!sendRequest("http://183.136.156.2:50000/upload", destPath)){ |
|
|
|
return R.fail("上传失败"); |
|
|
|
} |
|
|
|
String fileName="uploads/"+name; |
|
|
|
// 使用Hutool的FileUtil将MultipartFile保存到目标文件
|
|
|
|
String fileName= uploadFile(file); |
|
|
|
//
|
|
|
|
// String result = "";
|
|
|
|
// String infozong = "";
|
|
|
@ -224,7 +217,7 @@ public class Qwen72bController extends BaseController { |
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// String strings = completableFuture.get();
|
|
|
|
CompletableFuture<String> checkPlaceNameData = fetchDataAsync("http://183.136.156.2:50000/checkPlaceName?filename=" + fileName) |
|
|
|
CompletableFuture<String> checkPlaceNameData = fetchDataAsync(chatUrl+"/checkPlaceName?filename=" + fileName) |
|
|
|
.thenApply(data -> { |
|
|
|
List<HashMap> entity = null; |
|
|
|
if (StringUtils.isNotBlank(data)) { |
|
|
@ -248,7 +241,7 @@ public class Qwen72bController extends BaseController { |
|
|
|
}); |
|
|
|
|
|
|
|
CompletableFuture<String> checkCompanyNameData = checkPlaceNameData |
|
|
|
.thenCompose(result -> fetchDataAsync("http://183.136.156.2:50000/checkCompanyName?filename=" + fileName)) |
|
|
|
.thenCompose(result -> fetchDataAsync(chatUrl+"/checkCompanyName?filename=" + fileName)) |
|
|
|
.thenApply(data -> { |
|
|
|
List<HashMap> entity = null; |
|
|
|
if (StringUtils.isNotBlank(data)) { |
|
|
@ -272,7 +265,7 @@ public class Qwen72bController extends BaseController { |
|
|
|
}); |
|
|
|
|
|
|
|
CompletableFuture<String> getDocumentErrorData = checkCompanyNameData |
|
|
|
.thenCompose(result -> fetchDataAsync("http://183.136.156.2:50000/getDocumentError?filename=" + fileName)) |
|
|
|
.thenCompose(result -> fetchDataAsync(chatUrl+"/getDocumentError?filename=" + fileName)) |
|
|
|
.thenApply(data -> { |
|
|
|
List<HashMap> entity = null; |
|
|
|
if (StringUtils.isNotBlank(data)) { |
|
|
@ -295,7 +288,7 @@ public class Qwen72bController extends BaseController { |
|
|
|
return info; |
|
|
|
}); |
|
|
|
CompletableFuture<String> checkRepeatTextData = getDocumentErrorData |
|
|
|
.thenCompose(result -> fetchDataAsync("http://183.136.156.2:50000/getDocumentError?filename=" + fileName+"§ionName="+content)) |
|
|
|
.thenCompose(result -> fetchDataAsync(chatUrl+"/getDocumentError?filename=" + fileName+"§ionName="+content)) |
|
|
|
.thenApply(data -> { |
|
|
|
// 对第二个接口的数据进行处理
|
|
|
|
List<HashMap> entity =null; |
|
|
@ -363,6 +356,201 @@ public class Qwen72bController extends BaseController { |
|
|
|
|
|
|
|
return future; |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping(value = "/sse-invoke", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void sse(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/stream?context="+context, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkPlaceName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkPlaceName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
//http://183.136.156.2:50000/see/checkPlaceName?filename="+fileName
|
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkPlaceName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkRepeatText", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkRepeatText(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkRepeatText?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkCompanyName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkCompanyName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkCompanyName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentError", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentError(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkDocumentErrorWeb?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkTitleName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkTitleName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("content") String context, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkTitleName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentAll/checkPlaceName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentAllCheckPlaceName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("uuid") String uuid, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = uploadFile(fileInfo,uuid); |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
//http://183.136.156.2:50000/see/checkPlaceName?filename="+fileName
|
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkPlaceName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentAll/checkRepeatText", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentAllCheckRepeatText(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("uuid") String uuid, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = "uploads/"+uuid; |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkRepeatText?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentAll/checkCompanyName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentAllCheckCompanyName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("uuid") String uuid, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = "uploads/"+uuid; |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkCompanyName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentAll/checkDocumentError", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentAllCcheckDocumentError(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("uuid") String uuid, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = "uploads/"+uuid; |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkDocumentErrorWeb?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@PostMapping(value = "/sse/checkDocumentAll/checkTitleName", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = "text/event-stream;charset=UTF-8") |
|
|
|
public void checkDocumentAllCheckTitleName(@RequestPart(name = "fileInfo", required = false) MultipartFile fileInfo, @RequestPart("uuid") String uuid, HttpServletResponse rp) { |
|
|
|
try { |
|
|
|
String fileName = "uploads/"+uuid; |
|
|
|
// String token = ApiTokenUtil.generateClientToken(API_KEY);
|
|
|
|
ChatGlmDto chatGlmDto = new ChatGlmDto(); |
|
|
|
SSEListener sseListener = new SSEListener(chatGlmDto, rp); |
|
|
|
ExecuteSSEUtil.executeSSE(chatUrl+"/sse/checkTitleName?filename="+fileName, sseListener, JSON.toJSONString(chatGlmDto)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
public String uploadFile(MultipartFile file) throws IOException { |
|
|
|
// String destDir = chatFilePath;
|
|
|
|
// String originalFilename = file.getOriginalFilename();
|
|
|
|
// if (originalFilename == null) {
|
|
|
|
// throw new IllegalArgumentException("文件名不能为空");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 获取文件的后缀
|
|
|
|
// String suffix = FileUtil.getSuffix(originalFilename);
|
|
|
|
//
|
|
|
|
// // 生成唯一的文件名
|
|
|
|
// String name = IdUtil.fastSimpleUUID() + "." + suffix;
|
|
|
|
//
|
|
|
|
// // 构建目标文件路径
|
|
|
|
// String destPath = destDir + File.separator + name;
|
|
|
|
//
|
|
|
|
// // 创建目标文件
|
|
|
|
// File destFile = new File(destPath);
|
|
|
|
// FileUtil.writeFromStream(file.getInputStream(), destFile);
|
|
|
|
// if(!sendRequest(chatUrl+"/upload", destPath)){
|
|
|
|
// throw new RuntimeException("上传文件失败");
|
|
|
|
// }
|
|
|
|
SysOssVo oss = ossService.upload(file); |
|
|
|
String fileName = oss.getOriginalName(); |
|
|
|
|
|
|
|
RequestBody requestBody = new MultipartBody.Builder() |
|
|
|
.setType(MultipartBody.FORM) |
|
|
|
.addFormDataPart("file", fileName, |
|
|
|
RequestBody.create(okhttp3.MediaType.parse(MediaType.APPLICATION_OCTET_STREAM_VALUE), file.getBytes())) |
|
|
|
.build(); |
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(chatUrl+"/upload") // 替换为你的Flask服务器地址
|
|
|
|
.post(requestBody) |
|
|
|
.build(); |
|
|
|
Response response = client.newCall(request).execute(); |
|
|
|
return "uploads/"+fileName; |
|
|
|
} |
|
|
|
public String uploadFile(MultipartFile file,String uuid) throws IOException { |
|
|
|
String destDir = chatFilePath; |
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
if (originalFilename == null) { |
|
|
|
throw new IllegalArgumentException("文件名不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取文件的后缀
|
|
|
|
String suffix = FileUtil.getSuffix(originalFilename); |
|
|
|
|
|
|
|
// 生成唯一的文件名
|
|
|
|
String name = uuid; |
|
|
|
|
|
|
|
// 构建目标文件路径
|
|
|
|
String destPath = destDir + File.separator + name; |
|
|
|
|
|
|
|
// 创建目标文件
|
|
|
|
File destFile = new File(destPath); |
|
|
|
FileUtil.writeFromStream(file.getInputStream(), destFile); |
|
|
|
if(!sendRequest(chatUrl+"/upload", destPath)){ |
|
|
|
throw new RuntimeException("上传文件失败"); |
|
|
|
} |
|
|
|
return "uploads/"+name; |
|
|
|
} |
|
|
|
public boolean sendRequest(String url,String filePath) { |
|
|
|
// 替换为你要上传的文件路径
|
|
|
|
File file = new File(filePath); |
|
|
@ -388,4 +576,9 @@ public class Qwen72bController extends BaseController { |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
@JobExecutor(name="ces") |
|
|
|
public ExecuteResult jobExecute(JobArgs jobArgs) { |
|
|
|
System.out.println(jobArgs.getJobParams()); |
|
|
|
return ExecuteResult.success("测试成功aaaaaaa"); |
|
|
|
} |
|
|
|
} |
|
|
|