|
|
|
@ -24,7 +24,9 @@ import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService;
|
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.utils.WordHelper; |
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.utils.WordMapUtils; |
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.vo.operation.StandardTicketInfoVo; |
|
|
|
|
import com.hnac.hzims.ticket.utils.AsposeUtil; |
|
|
|
|
import com.hnac.hzims.ticket.utils.ExcelUtil; |
|
|
|
|
import com.hnac.hzims.ticket.utils.ObjectUtils; |
|
|
|
|
import com.hnac.hzims.ticket.utils.PdfUtils; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.entity.*; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.service.ITwoTicketMatterLibraryService; |
|
|
|
@ -48,9 +50,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author hx |
|
|
|
@ -719,4 +724,92 @@ public class TicketMatterGroupServiceImpl extends BaseServiceImpl<TicketMatterGr
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void preview(Long id, HttpServletResponse response) { |
|
|
|
|
TicketMatterGroupVO detail = this.detail(id).getData(); |
|
|
|
|
String type = detail.getTicketType(); |
|
|
|
|
String fileName = ""; |
|
|
|
|
Map<String,Object> param = new HashMap(); |
|
|
|
|
if(TicketConstants.WordFileNameEnum.FIRST_WORK.getType().equals(type)) { |
|
|
|
|
fileName = "template/电气第一种工作票模版.docx"; |
|
|
|
|
param.put("matterLibraryListOne", this.convert(detail.getMatterLibraryListOne())); |
|
|
|
|
param.put("matterLibraryListTwo", this.convert(detail.getMatterLibraryListTwo())); |
|
|
|
|
param.put("matterLibraryListThree", this.convert(detail.getMatterLibraryListThree())); |
|
|
|
|
} |
|
|
|
|
else if(TicketConstants.WordFileNameEnum.SECOND_WORK.getType().equals(type)) { |
|
|
|
|
fileName = "template/电气第二种工作票模版.docx"; |
|
|
|
|
param.put("matterLibraryListSeven", this.convert(detail.getMatterLibraryListOne())); |
|
|
|
|
} |
|
|
|
|
else if(TicketConstants.WordFileNameEnum.MECHANICAL_WORK.getType().equals(type)) { |
|
|
|
|
fileName = "template/水力机械工作票模版.docx"; |
|
|
|
|
param.put("matterLibraryListEight", this.convert(detail.getMatterLibraryListOne())); |
|
|
|
|
param.put("matterLibraryListNine", this.convert(detail.getMatterLibraryListTwo())); |
|
|
|
|
param.put("matterLibraryListTen", this.convert(detail.getMatterLibraryListThree())); |
|
|
|
|
} |
|
|
|
|
else if(TicketConstants.WordFileNameEnum.SWITCH_OFF.getType().equals(type)) { |
|
|
|
|
fileName = "template/电气操作票.docx"; |
|
|
|
|
param.put("measureMapList", this.convert(detail.getMatterLibraryListOne())); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
XWPFDocument xwpfDocument = null; |
|
|
|
|
try { |
|
|
|
|
xwpfDocument = WordExportUtil.exportWord07(fileName, param); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
String wordPath = this.getFileSavePath() + detail.getName() +".docx"; |
|
|
|
|
try { |
|
|
|
|
this.exportTicketWord(Lists.newArrayList(xwpfDocument),wordPath); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
String pdfPath = this.getFileSavePath() + detail.getName() +".pdf"; |
|
|
|
|
AsposeUtil.wordToPdf(wordPath,pdfPath); |
|
|
|
|
PdfUtils.readPdf(response,pdfPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<Map> convert(List<? extends Object> param) { |
|
|
|
|
if(CollectionUtil.isNotEmpty(param)) { |
|
|
|
|
return IntStream.iterate(0,index -> index + 1).limit(param.size() > 4 ? param.size() : 4).mapToObj(index -> { |
|
|
|
|
if(index <= param.size() - 1) { |
|
|
|
|
Map result = ObjectUtils.obj2Map(param.get(index)); |
|
|
|
|
result.put("index",index + 1); |
|
|
|
|
result.put("measure",result.get("safetyMeasure")); |
|
|
|
|
result.put("status",null); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return new HashMap(); |
|
|
|
|
} |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
return IntStream.iterate(0,index -> index + 1).limit(4).mapToObj(index -> new HashMap()).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void exportTicketWord(List<XWPFDocument> documents, String savePath) throws IOException { |
|
|
|
|
FileOutputStream out = new FileOutputStream(savePath); |
|
|
|
|
try { |
|
|
|
|
for (XWPFDocument document : documents) { |
|
|
|
|
document.write(out); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch(Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
out.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getFileSavePath() { |
|
|
|
|
String os = System.getProperty("os.name").toLowerCase(); |
|
|
|
|
if("linux".equals(os)) { |
|
|
|
|
return pdfSavePath; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return "E://template/"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|