|
|
@@ -9,6 +9,7 @@ import com.goafanti.common.model.RdDetails;
|
|
|
import com.goafanti.common.utils.DateUtils;
|
|
|
import com.goafanti.common.utils.excel.FileUtils;
|
|
|
import com.goafanti.common.utils.excel.NewExcelUtil;
|
|
|
+import com.goafanti.common.utils.pdf.PDFUtils;
|
|
|
import com.goafanti.common.utils.word.WordUtils;
|
|
|
import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
|
import com.goafanti.core.mybatis.page.Pagination;
|
|
|
@@ -156,6 +157,7 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
|
|
|
@Override
|
|
|
public void pushDownloadDetailsWord(Long id, HttpServletResponse response) {
|
|
|
OutRdDetails bo = rdDetailsMapper.details(id);
|
|
|
+ // rdDetailsMapper.updateBrowseOrDownload(id, 1);
|
|
|
OutWordRdDetails data =new OutWordRdDetails();
|
|
|
BeanUtils.copyProperties(bo,data);
|
|
|
if (bo.getRdStartStr()!=null&&bo.getRdEndStr()!=null){
|
|
|
@@ -174,27 +176,64 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
|
|
|
@Override
|
|
|
public void pushDownloadDetailsPDF(Long id, HttpServletResponse response) {
|
|
|
OutRdDetails bo = rdDetailsMapper.details(id);
|
|
|
- rdDetailsMapper.updateBrowseOrDownload(id, 1);
|
|
|
+// rdDetailsMapper.updateBrowseOrDownload(id, 1);
|
|
|
OutWordRdDetails data = new OutWordRdDetails();
|
|
|
BeanUtils.copyProperties(bo, data);
|
|
|
- data.setStartEndTime(bo.getRdStartStr() + "~" + bo.getRdEndStr());
|
|
|
-
|
|
|
+ if (bo.getRdStartStr()!=null&&bo.getRdEndStr()!=null){
|
|
|
+ data.setStartEndTime(bo.getRdStartStr()+"~"+bo.getRdEndStr());
|
|
|
+ }else {
|
|
|
+ data.setStartEndTime("");
|
|
|
+ }
|
|
|
String tableName = data.getRdName();
|
|
|
- String url = uploadPath + "/tmp/RD_details_word_template.pdf";
|
|
|
-
|
|
|
- String realFileName = uploadPath+"/tmp/"+DateUtils.parseDateToStr(AFTConstants.YYYYMMDDHHMMSS_OUT, new Date()) + ".pdf";
|
|
|
-// response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
|
|
|
+ String attName = data.getRdName()+new Date().getTime() + ".pdf";
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
|
|
Document document=new Document();
|
|
|
try {
|
|
|
- PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(realFileName));
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, tableName,attName);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(realFileName);
|
|
|
+ PdfWriter writer = PdfWriter.getInstance(document, outputStream);
|
|
|
document.open();
|
|
|
- document.add(new Paragraph("Hello Word"));
|
|
|
+ Paragraph paragraph = new Paragraph(data.getRdName(), PDFUtils.getTitleFont());
|
|
|
+ paragraph.setAlignment(1);
|
|
|
+ document.add(paragraph);
|
|
|
+ addDocument(document,"项目起止时间: ",data.getStartEndTime());
|
|
|
+ addDocument(document,"公司名称: ",data.getUserName());
|
|
|
+ addDocument(document,"项目负责人: ",data.getConsultantName());
|
|
|
+ addDocument(document,"技术领域: ",data.getTechnicalField());
|
|
|
+ addDocument(document,"技术来源: ",data.getTechnologySource());
|
|
|
+ addDocument(document,"研发费用总预计: ",data.getTotalAmount().toEngineeringString()+" 万元");
|
|
|
+ addDocument(document,"研发目的/立项目的/实施方式",null);
|
|
|
+ addContent(document," "+data.getRdObjective());
|
|
|
+ addDocument(document,"核心技术/创新点",null);
|
|
|
+ addContent(document," "+data.getCoreTechnology());
|
|
|
+ addDocument(document,"成果",null);
|
|
|
+ addContent(document," "+data.getAchieveResults());
|
|
|
document.close();
|
|
|
+ outputStream.close();
|
|
|
+ FileUtils.writeBytes(realFileName, response.getOutputStream());
|
|
|
+ FileUtils.deleteFile(realFileName);
|
|
|
} catch (DocumentException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void addDocument(Document document, String key, String value) throws DocumentException {
|
|
|
+ if(key!=null)document.add(new Chunk(key,PDFUtils.getBigFont()));
|
|
|
+ Phrase phrase = new Phrase(value, PDFUtils.getFont());
|
|
|
+ phrase.setLeading(40);
|
|
|
+ if(value!=null)document.add(phrase);
|
|
|
+ document.add(Chunk.NEWLINE);
|
|
|
+ }
|
|
|
+ private void addContent(Document document, String value) throws DocumentException {
|
|
|
+ Phrase phrase = new Phrase(value, PDFUtils.getFont());
|
|
|
+ phrase.setLeading(25);
|
|
|
+ if(value!=null)document.add(phrase);
|
|
|
+ document.add(Chunk.NEWLINE);
|
|
|
+ }
|
|
|
}
|