123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- package cn.cslg.pas;
- import cn.cslg.pas.common.model.dify.ClaimExplainVO;
- import cn.cslg.pas.common.model.dify.DifyChatMessageDTO;
- import cn.cslg.pas.common.model.dify.GenerateInstructAnswerVO;
- import cn.cslg.pas.common.utils.ClaimUtils.ClaimSplitUtils;
- import cn.cslg.pas.common.utils.FileUtils;
- import cn.cslg.pas.common.utils.commonUtils.BusinessUtil;
- import cn.cslg.pas.common.vo.PatentRightParams;
- import cn.cslg.pas.common.vo.RePatentClaim;
- import cn.cslg.pas.domain.dify.GetInstructAnswerDTO;
- import cn.cslg.pas.service.common.DifyService;
- import cn.cslg.pas.service.dify.GenerateInstructionService;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson2.JSON;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.xssf.usermodel.XSSFCell;
- import org.apache.poi.xssf.usermodel.XSSFRow;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.apache.poi.xwpf.usermodel.XWPFDocument;
- import org.junit.jupiter.api.Test;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- @SpringBootTest
- public class DifyTest {
- @Autowired
- private GenerateInstructionService generateInstructionService;
- @Autowired
- private DifyService difyService;
- @Test
- public void checkFile() throws Exception {
- // String path = "E:\\temfile\\poi\\test1.docx";
- // File file=new File(path);
- //
- // XWPFDocument doc = poiService.checkPatentFile(path);
- // FileOutputStream out = new FileOutputStream("E:\\temfile\\poi\\output2.docx");
- // doc.write(out);
- // out.close();
- // doc.close();
- }
- @Test
- public void checkFile1() throws Exception {
- String text = "一种多功能汽车座舱,其特征在于,包括:\n地板机构;\n第一座椅机构,设置于所述地板机构,所述第一座椅机构用于作为驾驶舱供驾驶员进行驾驶操作;";
- String a = text.replaceAll("\n", "");
- System.out.println(a);
- }
- @Test
- public void test() throws Exception {
- String path = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250421-生成说明书-lrj-v1\\testModel\\claim-7.xlsx";
- Integer StartCell = 12;
- List<Map<String, Object>> maps = new ArrayList<>();
- List<String> claims = new ArrayList<>();
- // 打开Excel工作簿文件
- XSSFWorkbook workbook = new XSSFWorkbook(path);
- // 获取第一个工作表
- XSSFSheet sheet = workbook.getSheetAt(0);
- // 遍历所有行
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- XSSFRow row = sheet.getRow(i);
- XSSFCell cell = row.getCell(0);
- if (cell != null) {
- String claimValue = cell.getStringCellValue();
- if (claimValue != null && !claimValue.trim().equals("")) {
- PatentRightParams params = new PatentRightParams();
- params.setCountry("CN");
- params.setContent(claimValue);
- params.setPatentNo("CN");
- List<RePatentClaim> rePatentClaims = ClaimSplitUtils.formatPatentRight(params);
- String conversationId = null;
- for (int t = 0; t < rePatentClaims.size(); t++) {
- Map<String, Object> map = new HashMap<>();
- RePatentClaim rePatentClaim = rePatentClaims.get(t);
- ClaimExplainVO claimExplainVO = null;
- String claimContent = rePatentClaim.getContent();
- GetInstructAnswerDTO getInstructAnswerDTO = new GetInstructAnswerDTO();
- getInstructAnswerDTO.setClaim(claimContent);
- getInstructAnswerDTO.setIndex(t + 1);
- getInstructAnswerDTO.setType("g&implementation");
- if (conversationId != null) {
- getInstructAnswerDTO.setConversationId(conversationId);
- }
- long start = System.currentTimeMillis();
- GenerateInstructAnswerVO generateInstructAnswerVO = generateInstructionService.getAnswerFromAI(getInstructAnswerDTO);
- long end = System.currentTimeMillis();
- generateInstructAnswerVO.getConversionId();
- String answer = generateInstructAnswerVO.getAnswer();
- if (generateInstructAnswerVO.getConversionId() != null && conversationId == null) {
- conversationId = generateInstructAnswerVO.getConversionId();
- }
- claimExplainVO = JSONObject.parseObject(answer, ClaimExplainVO.class);
- long overTime = (end - start) / 1000;
- map.put("claimExplainVO", claimExplainVO);
- map.put("claim", claimContent);
- map.put("overTime", overTime);
- maps.add(map);
- }
- }
- }
- }
- for (int i = 0; i < maps.size(); i++) {
- Map<String, Object> map = maps.get(i);
- ClaimExplainVO claimExplainVO = (ClaimExplainVO) map.get("claimExplainVO");
- String claim = (String) map.get("claim");
- long overTime = (long) map.get("overTime");
- XSSFRow row = sheet.getRow(i + 1);
- if (row == null) {
- row = sheet.createRow(i + 1);
- }
- XSSFCell cell1 = row.getCell(1);
- if (cell1 == null) {
- cell1 = row.createCell(1);
- }
- cell1.setCellValue(claim);
- XSSFCell cell2 = row.getCell(StartCell);
- if (cell2 == null) {
- cell2 = row.createCell(StartCell);
- }
- String jsons = JSONObject.toJSONString(claimExplainVO);
- cell2.setCellValue(jsons);
- XSSFCell cell3 = row.getCell(StartCell + 1);
- if (cell3 == null) {
- cell3 = row.createCell(StartCell + 1);
- }
- cell3.setCellValue(overTime);
- }
- // 关闭工作簿
- String outPath = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250421-生成说明书-lrj-v1\\testModel\\claim-2.xlsx";
- FileOutputStream out = new FileOutputStream(outPath);
- workbook.write(out);
- out.flush();
- out.close();
- workbook.close();
- }
- public String chatMessage(String cl, String f1, String f2, String f3, String f4, String f5, String f6) throws Exception {
- String key = "app-yW12smqvBIGmocUDeeG1B8DF";
- Map<String, Object> map = new HashMap<>();
- map.put("cl", cl);
- map.put("f1", f1);
- map.put("f2", f2);
- map.put("f3", f3);
- map.put("f4", f4);
- map.put("f5", f5);
- map.put("f6", f6);
- DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
- difyChatMessageDTO.setUser("1");
- difyChatMessageDTO.setResponseMode("blocking");
- difyChatMessageDTO.setQuery("123");
- difyChatMessageDTO.setInputs(map);
- String re = difyService.chatMessage(difyChatMessageDTO, key);
- JSONObject jsonObject = JSONObject.parseObject(re);
- String answer = jsonObject.get("answer").toString();
- return answer;
- }
- @Test
- public void pingfen() throws Exception {
- String path = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250421-生成说明书-lrj-v1\\testModel\\claim-8.xlsx";
- List<Map<String, Object>> maps = new ArrayList<>();
- List<String> claims = new ArrayList<>();
- // 打开Excel工作簿文件
- XSSFWorkbook workbook = new XSSFWorkbook(path);
- // 获取第一个工作表
- XSSFSheet sheet = workbook.getSheetAt(0);
- // 遍历所有行
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- XSSFRow row = sheet.getRow(i);
- XSSFCell cell1 = row.getCell(1);
- String v1 = cell1.getStringCellValue();
- XSSFCell cell2 = row.getCell(2);
- String v2 = cell2.getStringCellValue();
- XSSFCell cell3 = row.getCell(4);
- String v3 = cell3.getStringCellValue();
- XSSFCell cell4 = row.getCell(6);
- String v4 = cell4.getStringCellValue();
- XSSFCell cell5 = row.getCell(8);
- String v5 = cell5.getStringCellValue();
- XSSFCell cell6 = row.getCell(10);
- String v6 = cell6.getStringCellValue();
- XSSFCell cell7 = row.getCell(12);
- String v7 = cell7.getStringCellValue();
- String a = this.chatMessage(v1, v2, v3, v4, v5, v6, v7);
- XSSFCell xssfCell8 = row.createCell(14);
- xssfCell8.setCellValue(a);
- }
- String outPath = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250421-生成说明书-lrj-v1\\testModel\\claim-2.xlsx";
- FileOutputStream out = new FileOutputStream(outPath);
- workbook.write(out);
- out.flush();
- out.close();
- workbook.close();
- }
- @Test
- public void TestWord() throws Exception {
- Integer start=10;
- String path = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250310-技术交底书自动生成-lrj-v1\\question3.xlsx";
- // 打开Excel工作簿文件
- XSSFWorkbook workbook = new XSSFWorkbook(path);
- // 获取第一个工作表
- XSSFSheet sheet = workbook.getSheetAt(0);
- // 遍历所有行
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- XSSFRow row = sheet.getRow(i);
- XSSFCell cell1 = row.getCell(0);
- String value = cell1.getStringCellValue();
- long a1 =System.currentTimeMillis();
- String a = this.chatMessageGetOpt(value);
- long b1 =System.currentTimeMillis();
- XSSFCell xssfCell8 = row.createCell(start);
- xssfCell8.setCellValue(a);
- XSSFCell xssfCell9 = row.createCell(start+1);
- long overTime =(b1-a1)/1000;
- xssfCell9.setCellValue(overTime);
- }
- String outPath = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250310-技术交底书自动生成-lrj-v1\\question4.xlsx";
- FileOutputStream out = new FileOutputStream(outPath);
- workbook.write(out);
- out.flush();
- out.close();
- workbook.close();
- }
- public String chatMessageGetOpt(String query) throws Exception {
- String key = "app-RJf21elYKkzosEbLQwjl7gqi";
- Map<String, Object> map = new HashMap<>();
- DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
- difyChatMessageDTO.setUser("1");
- difyChatMessageDTO.setResponseMode("blocking");
- difyChatMessageDTO.setQuery(query);
- difyChatMessageDTO.setInputs(map);
- String re = difyService.chatMessage(difyChatMessageDTO, key);
- JSONObject jsonObject = JSONObject.parseObject(re);
- String answer = jsonObject.get("answer").toString();
- return answer;
- }
- @Test
- public void test3(){
- String cleanText ="";
- String a ="1.一种,13开发";
- String regex = "[\u4e00-\u9fff]+"; // 匹配连续中文字符
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(a);
- while (matcher.find()) {
- cleanText=matcher.group();
- break;
- }
- System.out.println(cleanText);
- }
- }
|