Commit 05f76520 authored by 徐俊's avatar 徐俊
parents a95a349f 456d64f9
......@@ -15,7 +15,6 @@ import com.yiboshi.science.service.ComFileService;
import com.yiboshi.science.service.ComProjectService;
import com.yiboshi.science.service.ComProjectTaskService;
import com.yiboshi.science.service.SystemParameterService;
import com.yiboshi.science.utils.PdfUtil;
import com.yiboshi.science.utils.ProjectInfoToPDF;
import com.yiboshi.science.utils.StringUtil;
import io.swagger.annotations.Api;
......@@ -87,25 +86,6 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
return ResponseDataModel.ok(comProjectService.getCount(e));
}
@ApiOperation(value = "项目信息导出", httpMethod = "POST", notes = "项目信息导出")
@RequestMapping("/export1/{id}")
@PostMapping
public void export1(@PathVariable String id) {
comProjectService.export(id, request, response);
}
@ApiOperation(value = "项目信息导出", httpMethod = "POST", notes = "项目信息导出")
@RequestMapping("/export/{id}")
@PostMapping
public ResponseDataModel<byte[]> export(@PathVariable String id) {
try {
return ResponseDataModel.ok(PdfUtil.createPDF(response, "tmp-report.html", new ComProject()));
} catch (Exception e) {
return new ResponseDataModel(ResponseCode.SERVER_ERROR, "");
}
}
/**
* 根据id获取项目信息
*
......
......@@ -21,13 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 功能:任务书表 接口
......@@ -157,7 +155,8 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi
// 生成PDF文件字节数组
// byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(dto);
byte[] pdfBytes = TaskToPDF.createContractPdf(dto);
// byte[] pdfBytes = TaskToPDF.createContractPdf(dto);
byte[] pdfBytes = TalentToPDF.createContractPdf(dto);
// 设置响应头
response.setContentType("application/pdf");
String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1");
......
......@@ -253,7 +253,7 @@ public class ComProjectAssignServiceImpl extends BaseServiceImpl<ComProjectAssig
economyScore = new BigDecimal(df1.format(economyScore));
}
totalScore = technologyScore.add(economyScore);
calculateScore = technologyAverageScore.multiply(new BigDecimal(0.8)).add(economyAverageScore.multiply(new BigDecimal(0.2)));
calculateScore = technologyAverageScore.multiply(new BigDecimal(1)).add(economyAverageScore.multiply(new BigDecimal(1)));
calculateScore = new BigDecimal(df1.format(calculateScore));
if (list.size() > personCount)
completed = 0;
......
......@@ -17,7 +17,6 @@ import com.yiboshi.science.entity.ComProjectConclusion;
import com.yiboshi.science.param.query.ComProjectConclusionQueryVO;
import com.yiboshi.science.service.*;
import com.yiboshi.science.utils.DateUtils;
import com.yiboshi.science.utils.PdfUtil;
import org.apache.velocity.VelocityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -339,7 +338,7 @@ public class ComProjectConclusionServiceImpl extends BaseServiceImpl<ComProjectC
context.put("day", day >= 10 ? day : "0" + day);
try (ServletOutputStream outputStream = response.getOutputStream()) {
PdfUtil.pdfFile(context, "/template/demo.html", outputStream);
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -963,23 +963,7 @@ public class ComProjectServiceImpl extends BaseServiceImpl<ComProjectDAO, ComPro
public void export(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
String filename = System.currentTimeMillis() + ".pdf";
response.reset();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline; filename=" + URLUtil.encode(filename, CharsetUtil.CHARSET_UTF_8));
VelocityContext context = new VelocityContext();
Calendar calendar = Calendar.getInstance();
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DATE);
context.put("reportYear", 2024);
context.put("year", calendar.get(Calendar.YEAR));
context.put("month", month >= 10 ? month : "0" + month);
context.put("day", day >= 10 ? day : "0" + day);
try (ServletOutputStream outputStream = response.getOutputStream()) {
PdfUtil.pdfFile(context, "/template/tmp-report.html", outputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
......
......@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.yiboshi.science.utils.PdfUtil.*;
import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;
public class TaskToPDF {
......@@ -259,88 +260,4 @@ public class TaskToPDF {
}
document.add(projTable);
}
private static void addTablePageCell(Table table, String label, String value, Integer labelColspan, Integer valueColspan, PdfFont font) {
if (Objects.isNull(labelColspan))
labelColspan = 1;
if (Objects.isNull(valueColspan))
valueColspan = 1;
Cell labelCell = new Cell(1, labelColspan);
labelCell.setMinHeight(36f);
labelCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
labelCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
labelCell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.1f)); // 设置边框宽度
labelCell.add(new Paragraph(label != null ? label.toString() : "").setFont(font).setFontSize(15));
labelCell.setBorder(Border.NO_BORDER);
table.addCell(labelCell);
Cell valueCell = new Cell(1, valueColspan);
valueCell.setPadding(3f);
valueCell.setMinHeight(36f);
valueCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
valueCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
// 只设置下边框
valueCell.setBorderTop(Border.NO_BORDER);
valueCell.setBorderLeft(Border.NO_BORDER);
valueCell.setBorderRight(Border.NO_BORDER);
valueCell.setBorderBottom(unitedBorder);
valueCell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(15));
table.addCell(valueCell);
}
private static void addValueCell(Table table, String label, Integer labelColspan, String value, Integer valueColspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
addCell(table, label, labelColspan, null, height, font, fontSize, vertical, horizontal);
addCell(table, value, valueColspan, null, height, font, fontSize, vertical, horizontal);
}
private static void addCell(Table table, Object value, Integer colspan, Integer rowspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
if (Objects.isNull(font))
font = createFont("simsun.ttc");
if (Objects.isNull(fontSize))
fontSize = 10.5f;
if (Objects.isNull(height))
height = 25.5f;
if (Objects.isNull(colspan))
colspan = 1;
if (Objects.isNull(rowspan))
rowspan = 1;
if (Objects.isNull(vertical))
vertical = VerticalAlignment.MIDDLE;
if (Objects.isNull(horizontal))
horizontal = HorizontalAlignment.CENTER;
Cell cell = new Cell(rowspan, colspan);
cell.setPadding(5f);
cell.setMinHeight(height);
cell.setVerticalAlignment(vertical);
cell.setHorizontalAlignment(horizontal);
cell.setBorderRight(unitedBorder);
cell.setBorderBottom(unitedBorder);
// 创建段落并检查字体
cell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(fontSize));
table.addCell(cell);
}
// 为了保持兼容性,添加原有方法的重载
private static void setParagraph(Document document, Object value, PdfFont font, float FontSize, boolean bold) throws DocumentException {
Paragraph paragraph = new Paragraph(value != null ? value.toString() : "")
.setFont(font)
.setFontSize(FontSize)
.setTextAlignment(TextAlignment.LEFT) // 设置文字对齐方式
.setMarginLeft(1f); // 设置左缩进
if (bold) {
paragraph.setBold();
}
document.add(paragraph);
}
private static String numberTo(int number) {
char[] cs = "零一二三四五六七八九".toCharArray();
String temp = "";
while (number > 0) {
temp += cs[number % 10];
number /= 10;
}
return temp;
}
}
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