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> maps = new ArrayList<>(); List 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 rePatentClaims = ClaimSplitUtils.formatPatentRight(params); String conversationId = null; for (int t = 0; t < rePatentClaims.size(); t++) { Map 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 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 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> maps = new ArrayList<>(); List 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 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); } }