Commit 68a92b5e authored by liangyb's avatar liangyb

#251-0 2024705 ai生成文档修改,结构化非结构化报表添加修改,评审说明修改

parent 361e4d19
......@@ -2,6 +2,7 @@ package com.gx.obe.evaluation.step.composite;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.CallBack;
......@@ -41,6 +42,7 @@ public class AiEvalLeftButton extends ImageButton{
// private ShowAiProcessShell menuTipShell;
private MouseListener listener;
private ShowAiProcessShell showAiProcessShell;
private File downLoadPath;
public static Color BG = ColorConstants.SKIN_BG;
public AiEvalLeftButton(Composite parent, int style,TenderProjectEntity curTender) {
super(parent, SWT.CENTER|SWT.NONE);
......@@ -79,6 +81,10 @@ public class AiEvalLeftButton extends ImageButton{
public void mouseEnter(MouseEvent e) {
HttpUrl httpUrl = HttpUtils.getProjectHttpUrl(curTender, PropertiesUtils.getWebserviceProperty(WebserviceConstants.GET_AI_RESULT_METHOD, "bidOpeningHS.do?downloadOpenBidSupplierAiResult"));
HttpResponse httpResponse = HttpUtils.doPost(httpUrl);
downLoadPath = new File(FileConstants.getBiddingFilePath(curTender.getId()) + "ai.pdf");
if(StringUtils.isNotEmpty(downLoadPath.getAbsolutePath()) && downLoadPath.exists()) {
return;
}
downloadBiddingFile(httpResponse);
// showAiProcessShell = new ShowAiProcessShell(getShell(), EvalLeftButton1.this, 0, "");
// if(null != showAiProcessShell && !showAiProcessShell.isDisposed()){
......@@ -98,7 +104,6 @@ public class AiEvalLeftButton extends ImageButton{
});
}
private void downloadBiddingFile(HttpResponse httpResponse){
String downUrl = "";
if(null == httpResponse.getContent() || "".equals(httpResponse.getContent())){
// LOG.debug("服务器返回数据为空!");
......@@ -111,13 +116,9 @@ public class AiEvalLeftButton extends ImageButton{
if(StringUtils.isNotEmpty(packageAiType) && packageAiType.equals(CommonEnum.YES) && StringUtils.isNotEmpty(downUrl) ){
// LOG.debug("下载地址获取成功"+downUrl);
// callBackMsg(true, "下载地址获取成功,开始解析下载地址...");
String downLoadPath = new File(FileConstants.getBiddingFilePath(curTender.getId()) + "ai.pdf").getAbsolutePath();
downLoadFile(downUrl, downLoadPath);
String downLoadPaths = downLoadPath.getAbsolutePath();
downLoadFile(downUrl, downLoadPaths);
}else {
String progress = httpResponse.getDataParam("progress");
String waitTime = httpResponse.getDataParam("waitTime");
showAiProcessShell = new ShowAiProcessShell(getShell(), AiEvalLeftButton.this, ObjectUtils.getIntValue(progress, 0), waitTime);
......@@ -128,12 +129,17 @@ public class AiEvalLeftButton extends ImageButton{
}
}
private void downLoadFile(String downLoadUrl, String savePath){
private void downLoadFile(String downLoadUrl, String downLoadPaths){
// callBackMsg("开始下载招标文件...");
HttpURLDown httpURLDown = new HttpURLDown(downLoadUrl, savePath, new CallBack() {
HttpURLDown httpURLDown = new HttpURLDown(downLoadUrl, downLoadPaths, new CallBack() {
});
try {
showAiProcessShell = new ShowAiProcessShell(getShell(), AiEvalLeftButton.this, ObjectUtils.getIntValue("0", 0), "10s");
showAiProcessShell.open();
boolean downFlag = httpURLDown.downLoad("标书比对相似度分析");
showAiProcessShell.close();
showAiProcessShell = new ShowAiProcessShell(getShell(), AiEvalLeftButton.this, ObjectUtils.getIntValue("100", 0), "0s");
showAiProcessShell.open();
// callBackMsg("招标文件下载结束!");
// 下载成功并且是.zip文件才进行解压操作
if(downFlag){
......@@ -143,7 +149,7 @@ public class AiEvalLeftButton extends ImageButton{
listener = new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(!groupButton.getEnabled()) return;
RuntimeUtils.openFIle(new File(savePath));
RuntimeUtils.openFIle(new File(downLoadPaths));
}
};
groupButton.addMouseListener(listener);
......
......@@ -820,6 +820,7 @@ public abstract class BaseDateSet implements IWordDataSet{
priceScoreDate.init(tenderProject);
List<Map<String, Object>> tableColList;
String[] fields;
reportDataSet.put("jingnengStruct", isStruct ? "1" : "0");
if(isStruct) {
fields = new String[] {
"开标价格 --(含税)&&bidPrice0",
......@@ -833,8 +834,8 @@ public abstract class BaseDateSet implements IWordDataSet{
};
}else {
fields = new String[] {
"开标价格 --&&bidPrice0",
"修正后投标报价&&evaluationPrice0",
"开标价格 (--)&&bidPrice0",
"修正后投标报价 (--)&&evaluationPrice0",
"修正原因&&modifyReason0",
"基准价&&basePrice",
"价格得分&&priceFinalScore"
......@@ -906,8 +907,14 @@ public abstract class BaseDateSet implements IWordDataSet{
List<Map<String, Object>> factorList = new ArrayList<Map<String, Object>>();
int index = 1;
for(String field : fields){
if(field.contains("--") && unit != null) {
if(field.contains("--")) {
if(unit != null) {
field = field.replaceAll("--", unit);
}else {
//给默认值
field = field.replaceAll("--", "元");
}
}
Map<String, Object> colMap = new HashMap<String, Object>();
String[] f = field.split("&&");
......
......@@ -779,25 +779,25 @@ public class JingNengEvaluationReportDataSet extends BaseDateSet {
private void getFactorMessage() {
EvaluationFactor evaluationFactor =evaluationFactorService.getPriceEvaluationFactor(tenderProject.getId());
String formula = null;
String evalStructMessage = null;
String evalStructMessage = "";
PriceParam priceParam =null;
if(evaluationFactor != null) {
priceParam = PriceParam.deserializePriceParam(evaluationFactor.getComputerParams());
}
if (priceParam != null) {
String separator=System.getProperty("line.separator");
//String separator=System.getProperty("line.separator");
formula = priceParam.getFormula();
evalStructMessage = priceParam.getEvalStructMessage();
}
if (!StringUtils.isEmpty(formula)) {
boolean isStruct = parserStructProject();
if (!StringUtils.isEmpty(evalStructMessage) && isStruct) {
if (isStruct) {
formula = Messages.EvalExplainPrice + ":" + evalStructMessage + "\n\n" + Messages.BidExplainPrice + ":"+ evaluationFactor.getMemo();
}
// if(!StringUtils.isEmpty(evaluationFactor.getMemo()) && !isStruct) {
// formula = formula + "\n\n" + Messages.EvalExplain + ":" + evaluationFactor.getMemo();
// }
if(!StringUtils.isEmpty(evaluationFactor.getMemo()) && !isStruct) {
formula = Messages.EvalExplain + ":" + evaluationFactor.getMemo();
}
reportDataSet.putParam("formula", formula);
}
//获取商务技术打分权重
......
......@@ -4,68 +4,216 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URLDecoder;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import com.sun.media.Log;
public class WordAddBreakUtils {
private static Logger logger = Logger.getLogger(WordAddBreakUtils.class);
private final static String BOOK_MARK = "formula_param";
private final static String BREAK="\\n";
private final static String BOOK_STRUCT_MARK = "jingnengStruct_param";
private final static String TABLE_TITLES = "§";
private final static String TABLE_TITLE = "∮";
private final static String BREAK = "\\n";
public static void writer(String inputSrc, String outSrc) {
try {
File file = new File(inputSrc);
// 获取文件输
FileInputStream fileInputStream = new FileInputStream (file);
// 获取文件输
FileInputStream fileInputStream = new FileInputStream(file);
// 创建操作word的对象
XWPFDocument doc = new XWPFDocument(fileInputStream);
List<XWPFParagraph> paragraphs = doc.getParagraphs();
for(XWPFParagraph p :paragraphs){
boolean removeContent = true;
for (int i = 0; i < paragraphs.size(); i++) {
XWPFParagraph p = paragraphs.get(i);
CTP ctp = p.getCTP();
for(int i=0;i<ctp.sizeOfBookmarkStartArray();i++){
CTBookmark ctBookmark = ctp.getBookmarkStartArray(i);
if(ctBookmark.getName().equals(BOOK_MARK)){
for (int j = 0; j < ctp.sizeOfBookmarkStartArray(); j++) {
CTBookmark ctBookmark = ctp.getBookmarkStartArray(j);
if (ctBookmark.getName().equals(BOOK_MARK)) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
//需要替换的文本
// 需要替换的文本
String text = r.getText(0);
//替换指定的文本
r.setText("",0);
// 替换指定的文本
r.setText("", 0);
String[] split = text.split(BREAK);
for(String textSlice : split){
for (String textSlice : split) {
r.setText(textSlice);
r.addBreak();
}
}
}
}
if (ctBookmark.getName().equals(BOOK_STRUCT_MARK)) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
// 需要替换的文本
String text = r.getText(0);
if("1".equals(text)) {
// 标记从此书签开始删除后续内容
removeContent = false;
break;
}
}
}
}
}
}
try {
if (removeContent) {
deleteAfterMarker(doc,TABLE_TITLES);
}else {
//updateTables(doc);
}
}catch (Exception e) {
Log.error(e.getMessage());
}
doc.write(new FileOutputStream(outSrc));
System.out.println("评标报告替换完成");
logger.error("评标报告替换完成");
} catch (IOException e) {
logger.error("评标报告替换失败");
e.printStackTrace();
}
}
/**
* 适配删除含有特殊字段的表格和文本段落
* @param document
* @param marker
*/
private static void deleteAfterMarker(XWPFDocument document, String marker) {
// 遍历段落
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (int i = 0; i < paragraphs.size(); i++) {
XWPFParagraph paragraph = paragraphs.get(i);
String text = paragraph.getText();
if (text.contains(marker)) {
document.removeBodyElement(document.getPosOfParagraph(paragraph));
i--;
}
}
List<XWPFTable> tables = document.getTables();
for (int i = 0; i < tables.size(); i++) {
XWPFTable table = tables.get(i);
XWPFTableRow firstRow = table.getRow(0);
if (firstRow != null) {
XWPFTableCell firstCell = firstRow.getCell(0);
if (firstCell != null) {
String cellText = firstCell.getText();
if (cellText.contains(TABLE_TITLES)) {
document.removeBodyElement(document.getPosOfTable(tables.get(i)));
i--;
}
}
}
}
}
/**
* 结构化表格样式适配
* @param document
*/
private static void updateTables(XWPFDocument document) {
List<XWPFTable> tables = document.getTables();
for (XWPFTable table : tables) {
XWPFTableRow firstRow = table.getRow(0);
if (firstRow != null) {
XWPFTableCell firstCell = firstRow.getCell(0);
if (firstCell != null) {
String cellText = firstCell.getText();
if (cellText.contains(TABLE_TITLE)) {
//adjustTableColumnWidths(table);
averageTableColumnWidths(table);
break;
}
}
}
}
}
private static void averageTableColumnWidths(XWPFTable table) {
int numColumns = table.getRow(0).getTableCells().size();
int tableWidth = 15 * 72; // You can set this value to any width you need
int columnWidth = tableWidth / numColumns;
for (XWPFTableRow row : table.getRows()) {
List<XWPFTableCell> cells = row.getTableCells();
for (XWPFTableCell cell : cells) {
CTTcPr tcPr = cell.getCTTc().addNewTcPr();
CTTblWidth tblWidth = tcPr.addNewTcW();
tblWidth.setType(STTblWidth.DXA);
tblWidth.setW(BigInteger.valueOf(columnWidth));
}
}
}
// private static void adjustTableColumnWidths(XWPFTable table) {
// int fixedWidth = 15 * 720; // 15 cm in twips (twentieths of a point)
//
// for (XWPFTableRow row : table.getRows()) {
// List<XWPFTableCell> cells = row.getTableCells();
// if (cells.size() > 1) {
// XWPFTableCell secondCell = cells.get(1);
// CTTcPr tcPr = secondCell.getCTTc().addNewTcPr();
// CTTblWidth tblWidth = tcPr.addNewTcW();
// tblWidth.setType(STTblWidth.DXA);
// tblWidth.setW(BigInteger.valueOf(fixedWidth));
// }
// }
// }
private static void adjustTableColumnWidths(XWPFTable table) {
int numColumns = table.getRow(0).getTableCells().size();
if (numColumns < 2) {
return; // 如果表格列数小于2,直接返回
}
// 计算每列宽度的比例
int firstColumnWidthPct = 5;
int otherColumnsWidthPct = (95 / (numColumns - 1));
// 遍历表格的每一行并调整列宽
for (XWPFTableRow row : table.getRows()) {
List<XWPFTableCell> cells = row.getTableCells();
for (int i = 0; i < cells.size(); i++) {
XWPFTableCell cell = cells.get(i);
if (i == 0) {
setCellWidth(cell, firstColumnWidthPct);
} else {
setCellWidth(cell, otherColumnsWidthPct);
}
}
}
}
private static void setCellWidth(XWPFTableCell cell, int widthPct) {
CTTc ctTc = cell.getCTTc();
CTTcPr tcPr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
CTTblWidth tblWidth = tcPr.isSetTcW() ? tcPr.getTcW() : tcPr.addNewTcW();
tblWidth.setType(STTblWidth.PCT);
tblWidth.setW(BigInteger.valueOf(widthPct * 50)); // 乘以50,因为Word中的列宽是1/50%
}
public static void main(String[] args) throws IOException, InvalidFormatException {
public static void main(String[] args) throws Exception {
//文件路径
String srcPath = "C:/bidFile/e6e67506e92c4b7b80aa4581fd1a4808/reportFile/临时报表/评标报告 .docx";
srcPath = URLDecoder.decode(srcPath, "UTF-8");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment