@ -81,7 +81,9 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -81,7 +81,9 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
lotteryProject . setType ( LotteryProjectDto . TypeEnum . ONESELF . getCode ( ) ) ;
lotteryProject . setStatus ( LotteryProjectDto . StatusEnum . TO_BE_EXTRACTED . getCode ( ) ) ;
lotteryProject . setStatusName ( LotteryProjectDto . StatusEnum . TO_BE_EXTRACTED . getDescribe ( ) ) ;
lotteryProject . setBidOpeningTime ( LocalDate . parse ( LocalDateTimeUtil . format ( param . getBidEvaluationTime ( ) , "yyyy-MM-dd" ) ) ) ;
if ( null ! = param . getBidEvaluationTime ( ) ) {
lotteryProject . setBidOpeningTime ( LocalDate . parse ( LocalDateTimeUtil . format ( param . getBidEvaluationTime ( ) , "yyyy-MM-dd" ) ) ) ;
}
UserInfo userInfo = userProvider . get ( ) ;
lotteryProject . setUserDeptId ( userInfo . getOrganizeId ( ) ) ;
//添加根子单数据
@ -102,7 +104,9 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -102,7 +104,9 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
throw new DataException ( "id不能为空" ) ;
}
LotteryProject lotteryProject = BeanUtil . copyProperties ( param , LotteryProject . class ) ;
lotteryProject . setBidOpeningTime ( LocalDate . parse ( LocalDateTimeUtil . format ( param . getBidEvaluationTime ( ) , "yyyy-MM-dd" ) ) ) ;
if ( null ! = param . getBidEvaluationTime ( ) ) {
lotteryProject . setBidOpeningTime ( LocalDate . parse ( LocalDateTimeUtil . format ( param . getBidEvaluationTime ( ) , "yyyy-MM-dd" ) ) ) ;
}
UserInfo userInfo = userProvider . get ( ) ;
;
lotteryProject . setUpdateId ( userInfo . getUserId ( ) ) ;
@ -332,18 +336,18 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -332,18 +336,18 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
}
//校验打印类型
LotteryProject lotteryProject = this . getById ( lotteryReview . getRelationId ( ) ) ;
if ( null = = lotteryReview . getExtractExpertsInfo ( ) ) {
if ( null = = lotteryReview . getExtractExpertsInfo ( ) ) {
throw new DataException ( "未抽取专家,无法打印[2]" ) ;
}
List < LotteryProjectDto . ExtractExpertsInfo > extractExpertsInfo = lotteryReview . getExtractExpertsInfo ( ) . stream ( ) . filter ( e - > e . getStatus ( ) . equals ( LotteryProjectDto . ConfirmEnum . JOIN . getCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < LotteryProjectDto . ExtractExpertsInfo > extractExpertsInfo = lotteryReview . getExtractExpertsInfo ( ) . stream ( ) . filter ( e - > e . getStatus ( ) . equals ( LotteryProjectDto . ConfirmEnum . JOIN . getCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
DownloadVO vo = DownloadVO . builder ( ) . build ( ) ;
switch ( lotteryProject . getLotteryType ( ) ) {
switch ( lotteryProject . getLotteryType ( ) ) {
case "1" :
if ( CollectionUtil . isEmpty ( extractExpertsInfo ) ) {
if ( CollectionUtil . isEmpty ( extractExpertsInfo ) ) {
throw new DataException ( "暂未有确认专家,无法打印" ) ;
}
try {
MockMultipartFile mockMultipartFile = expertPrinting ( "专家抽取结果打印.docx" , extractExpertsInfo ) ;
MockMultipartFile mockMultipartFile = expertPrinting ( "专家抽取结果打印.docx" , extractExpertsInfo , lotteryProject . getProjectName ( ) ) ;
String temporaryFilePath = fileApi . getPath ( FileTypeConstant . TEMPORARY ) ;
FileInfo fileInfo = fileUploadApi . uploadFile ( mockMultipartFile , temporaryFilePath , "专家抽取结果打印.docx" ) ;
vo . setName ( fileInfo . getFilename ( ) ) ;
@ -354,16 +358,16 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -354,16 +358,16 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
break ;
case "2" :
try {
if ( CollectionUtil . isEmpty ( extractExpertsInfo ) ) {
if ( CollectionUtil . isEmpty ( extractExpertsInfo ) ) {
throw new DataException ( "暂未有确认公司,无法打印" ) ;
}
MockMultipartFile mockMultipartFile = companyPrinting ( "招投标公司抽取结果打印.docx" , extractExpertsInfo ) ;
MockMultipartFile mockMultipartFile = companyPrinting ( "招投标公司抽取结果打印.docx" , extractExpertsInfo , lotteryProject . getProjectName ( ) ) ;
String temporaryFilePath = fileApi . getPath ( FileTypeConstant . TEMPORARY ) ;
FileInfo fileInfo = fileUploadApi . uploadFile ( mockMultipartFile , temporaryFilePath , "招投标公司抽取结果打印.docx" ) ;
vo . setName ( fileInfo . getFilename ( ) ) ;
vo . setUrl ( UploaderUtil . uploaderFile ( fileInfo . getFilename ( ) + "#" + "Temporary" ) + "&name=" + "招投标公司抽取结果打印.docx" ) ;
} catch ( Exception e ) {
log . error ( "专家 抽取结果打印异常" , e ) ;
log . error ( "公司 抽取结果打印异常" , e ) ;
}
break ;
}
@ -372,27 +376,42 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -372,27 +376,42 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
return vo ;
}
private MockMultipartFile expertPrinting ( String fileName , List < LotteryProjectDto . ExtractExpertsInfo > data ) throws Exception {
private MockMultipartFile expertPrinting ( String fileName , List < LotteryProjectDto . ExtractExpertsInfo > data , String projectName ) throws Exception {
try ( InputStream inputStream = ResourceUtil . getStream ( "jnpf/templete/浙江出版传媒股份有限公司ERP系统建设项目.docx" ) ;
XWPFDocument doc = new XWPFDocument ( inputStream ) ) {
// 找到标记位置的段落
XWPFParagraph placeholderParagraph = null ;
XWPFParagraph textParagraph = null ;
for ( XWPFParagraph paragraph : doc . getParagraphs ( ) ) {
if ( paragraph . getText ( ) . contains ( "{{table_here}}" ) ) {
placeholderParagraph = paragraph ;
break ;
}
if ( paragraph . getText ( ) . contains ( "{{projectName}}" ) ) {
textParagraph = paragraph ;
}
}
if ( placeholderParagraph = = null ) {
throw new IllegalStateException ( "Cannot find placeholder in the document." ) ;
}
// 删除包含占位符的段落
XWPFRun run = placeholderParagraph . getRuns ( ) . get ( 0 ) ;
run . setText ( run . getText ( 0 ) . replace ( "{{table_here}}" , "" ) , 0 ) ;
//替换项目名称
if ( textParagraph ! = null ) {
String join = StrUtil . join ( "" , textParagraph . getRuns ( ) . stream ( ) . map ( te - > te . getText ( 0 ) ) . collect ( Collectors . toList ( ) ) ) ;
XWPFRun xwpfRun = textParagraph . getRuns ( ) . get ( 0 ) ;
for ( XWPFRun textParagraphRun : textParagraph . getRuns ( ) ) {
textParagraphRun . setText ( "" ) ;
}
xwpfRun . setText ( join . replace ( "{{projectName}}" , projectName ) , 0 ) ;
}
// 在占位符位置插入表格
// 插入表格到占位符位置后
@ -463,18 +482,22 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -463,18 +482,22 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
}
}
private MockMultipartFile companyPrinting ( String fileName , List < LotteryProjectDto . ExtractExpertsInfo > data ) throws Exception {
private MockMultipartFile companyPrinting ( String fileName , List < LotteryProjectDto . ExtractExpertsInfo > data , String projectName ) throws Exception {
try ( InputStream inputStream = ResourceUtil . getStream ( "jnpf/templete/招投标公司打印.docx" ) ;
XWPFDocument doc = new XWPFDocument ( inputStream ) ) {
// 找到标记位置的段落
XWPFParagraph placeholderParagraph = null ;
XWPFParagraph textParagraph = null ;
for ( XWPFParagraph paragraph : doc . getParagraphs ( ) ) {
if ( paragraph . getText ( ) . contains ( "{{table_here}}" ) ) {
placeholderParagraph = paragraph ;
break ;
}
if ( paragraph . getText ( ) . contains ( "{{projectName}}" ) ) {
textParagraph = paragraph ;
}
}
if ( placeholderParagraph = = null ) {
@ -485,6 +508,16 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -485,6 +508,16 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
XWPFRun run = placeholderParagraph . getRuns ( ) . get ( 0 ) ;
run . setText ( run . getText ( 0 ) . replace ( "{{table_here}}" , "" ) , 0 ) ;
//替换项目名称
if ( textParagraph ! = null ) {
String join = StrUtil . join ( "" , textParagraph . getRuns ( ) . stream ( ) . map ( te - > te . getText ( 0 ) ) . collect ( Collectors . toList ( ) ) ) ;
XWPFRun xwpfRun = textParagraph . getRuns ( ) . get ( 0 ) ;
for ( XWPFRun textParagraphRun : textParagraph . getRuns ( ) ) {
textParagraphRun . setText ( "" ) ;
}
xwpfRun . setText ( join . replace ( "{{projectName}}" , projectName ) , 0 ) ;
}
// 在占位符位置插入表格
// 插入表格到占位符位置后
// XWPFTable table = doc.createTable();
@ -502,7 +535,7 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -502,7 +535,7 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
// // 填充表格数据
for ( LotteryProjectDto . ExtractExpertsInfo datum : data ) {
int i = 0 ;
int startRowNum = 1 ;
int startRowNum = 1 ;
for ( ExpertDto . ContactInformation contactInformation : datum . getContactInformation ( ) ) {
XWPFTableRow row = table . createRow ( ) ;
row . getCell ( 0 ) . setText ( datum . getId ( ) ) ;
@ -512,15 +545,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -512,15 +545,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
row . getCell ( 3 ) . setText ( contactInformation . getContactPhone ( ) ) ;
row . getCell ( 4 ) . setText ( datum . getRemark ( ) ) ;
if ( i = = 0 ) {
startRowNum = table . getRows ( ) . indexOf ( row ) ;
startRowNum = table . getRows ( ) . indexOf ( row ) ;
datum . setId ( "" ) ;
datum . setCompanyName ( "" ) ;
}
i + + ;
}
mergeCellsVertically ( table , 0 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 1 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 4 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 0 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 1 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 4 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
}
// 保存Word文档
@ -670,16 +703,20 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -670,16 +703,20 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
"]" ;
// List<LotteryProjectDto.ExtractExpertsInfo> data = JSON.parseArray(s, LotteryProjectDto.ExtractExpertsInfo.class);
List < LotteryProjectDto . ExtractExpertsInfo > data = JSON . parseArray ( s2 , LotteryProjectDto . ExtractExpertsInfo . class ) ;
try ( InputStream inputStream = new FileInputStream ( new File ( "/Users/yangzhenli/Documents/项目/jnpf /浙江出版传媒股份有限公司ERP系统建设项目.docx" ) ) ;
try ( InputStream inputStream = new FileInputStream ( new File ( "/Users/yangzhenli/code/jnpfsoft-jnpf-jnpf-java-cloud-/jnpf-tendering/jnpf-tendering-server/src/main/resources/jnpf/templete /浙江出版传媒股份有限公司ERP系统建设项目.docx" ) ) ;
XWPFDocument doc = new XWPFDocument ( inputStream ) ) {
// 找到标记位置的段落
XWPFParagraph placeholderParagraph = null ;
XWPFParagraph textParagraph = null ;
for ( XWPFParagraph paragraph : doc . getParagraphs ( ) ) {
if ( paragraph . getText ( ) . contains ( "{{table_here}}" ) ) {
placeholderParagraph = paragraph ;
break ;
}
if ( paragraph . getText ( ) . contains ( "{{projectName}}" ) ) {
textParagraph = paragraph ;
}
}
if ( placeholderParagraph = = null ) {
@ -689,6 +726,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -689,6 +726,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
// 删除包含占位符的段落
XWPFRun run = placeholderParagraph . getRuns ( ) . get ( 0 ) ;
run . setText ( run . getText ( 0 ) . replace ( "{{table_here}}" , "" ) , 0 ) ;
//替换项目名称
if ( textParagraph ! = null ) {
String join = StrUtil . join ( "" , textParagraph . getRuns ( ) . stream ( ) . map ( te - > te . getText ( 0 ) ) . collect ( Collectors . toList ( ) ) ) ;
XWPFRun xwpfRun = textParagraph . getRuns ( ) . get ( 0 ) ;
for ( XWPFRun textParagraphRun : textParagraph . getRuns ( ) ) {
textParagraphRun . setText ( "" ) ;
}
xwpfRun . setText ( join . replace ( "{{projectName}}" , "测试2" ) , 0 ) ;
}
// 在占位符位置插入表格
// 插入表格到占位符位置后
@ -706,7 +752,7 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -706,7 +752,7 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
// // 填充表格数据
for ( LotteryProjectDto . ExtractExpertsInfo datum : data ) {
int i = 0 ;
int startRowNum = 1 ;
int startRowNum = 1 ;
for ( ExpertDto . ContactInformation contactInformation : datum . getContactInformation ( ) ) {
XWPFTableRow row = table . createRow ( ) ;
row . getCell ( 0 ) . setText ( datum . getId ( ) ) ;
@ -716,15 +762,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
@@ -716,15 +762,15 @@ public class LotteryProjectServiceImpl extends ServiceImpl<LotteryProjectMapper,
row . getCell ( 3 ) . setText ( contactInformation . getContactPhone ( ) ) ;
row . getCell ( 4 ) . setText ( datum . getRemark ( ) ) ;
if ( i = = 0 ) {
startRowNum = table . getRows ( ) . indexOf ( row ) ;
startRowNum = table . getRows ( ) . indexOf ( row ) ;
datum . setId ( "" ) ;
datum . setCompanyName ( "" ) ;
}
i + + ;
}
mergeCellsVertically ( table , 0 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 1 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 4 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 0 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 1 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
mergeCellsVertically ( table , 4 , startRowNum , ( datum . getContactInformation ( ) . size ( ) - 1 ) + startRowNum ) ;
}
// // 在该行中添加三个单元格