Browse Source

# 工作票模板预览修改

zhongwei
haungxing 11 months ago
parent
commit
10075d0e1a
  1. 4
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java
  2. 2
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java
  3. 93
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java
  4. BIN
      hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx
  5. BIN
      hzims-service/ticket/src/main/resources/template/电气操作票.docx
  6. BIN
      hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx

4
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java

@ -108,8 +108,8 @@ public class TicketMatterGroupController extends BladeController {
@ApiImplicitParam(name = "type", value = "模板类型:2为工作票;1为操作票")
})
@ApiOperation(value = "预览")
public void preview(@RequestParam("id") Long id, @RequestParam("type") String type , HttpServletResponse response) throws Exception {
service.preview(id, type, response);
public void preview(@RequestParam("id") Long id , HttpServletResponse response) throws Exception {
service.preview(id, response);
}

2
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java

@ -64,4 +64,6 @@ public interface ITicketMatterGroupService extends BaseService<TicketMatterGroup
* @param response
*/
void newPreview(Long id, Integer type, Integer status, HttpServletResponse response);
void preview(Long id,HttpServletResponse response);
}

93
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java

@ -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/";
}
}
}

BIN
hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx

Binary file not shown.

BIN
hzims-service/ticket/src/main/resources/template/电气操作票.docx

Binary file not shown.

BIN
hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx

Binary file not shown.
Loading…
Cancel
Save