framework/src/main/java/com/yuanchu/mom/config/OpenFifer.java
@@ -27,7 +27,8 @@ @Value("${outPath}") private String outPath; @Value("${wordUrl}") private String wordUrl; public void addResourceHandlers(ResourceHandlerRegistry registry) { //é ç½®æ¦æªå¨è®¿é®éæèµæº @@ -38,6 +39,7 @@ //设置æä»¶èæè·¯å¾æ å° registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath+"/"); registry.addResourceHandler("/outPath/**").addResourceLocations("file:"+outPath); registry.addResourceHandler("/word/**").addResourceLocations("file:"+wordUrl+"/"); } @Override framework/src/main/java/com/yuanchu/mom/utils/GiveCode.java
@@ -21,7 +21,7 @@ String nums = num + ""; if(nums.length() == 1) nums = "00" + num; else if(nums.length() == 2) nums = "0" + num; return code + date2 + symbol + nums; return code + (date2==null?date:date2) + symbol + nums; } } inspect-server/pom.xml
@@ -32,6 +32,15 @@ <artifactId>poi-tl</artifactId> <version>1.12.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>5.3.18</version> </dependency> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc.free</artifactId> <version>5.2.0</version> </dependency> </dependencies> </project> inspect-server/src/main/java/com/yuanchu/mom/controller/InsReportController.java
@@ -1,6 +1,7 @@ package com.yuanchu.mom.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.yuanchu.mom.annotation.ValueAuth; import com.yuanchu.mom.dto.ReportPageDto; import com.yuanchu.mom.dto.SampleOrderDto; import com.yuanchu.mom.service.InsReportService; @@ -32,4 +33,11 @@ return Result.success(insReportService.pageInsReport(page, reportPageDto)); } @ApiOperation(value = "Word转HTML") @PostMapping("/wordToHtml") @ValueAuth public Result wordToHtml(String path) { return Result.success("è½¬æ¢æå", insReportService.wordToHtml(path)); } } inspect-server/src/main/java/com/yuanchu/mom/mapper/InsProductMapper.java
@@ -3,6 +3,8 @@ import com.yuanchu.mom.pojo.InsProduct; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import java.util.Map; /** * @author Administrator * @description é对表ãins_product(æ£éªé¡¹ç®)ãçæ°æ®åºæä½Mapper @@ -13,6 +15,8 @@ int selectOrderManDay(Integer orderId); Map<String, String> selectUserById(Integer userId); } inspect-server/src/main/java/com/yuanchu/mom/service/InsReportService.java
@@ -17,4 +17,6 @@ Map<String,Object> pageInsReport(Page page, ReportPageDto reportPageDto); String wordToHtml(String path); } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -11,24 +11,33 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; import com.deepoove.poi.config.ConfigureBuilder; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; import com.yuanchu.mom.dto.InsOrderPlanDTO; import com.yuanchu.mom.dto.SampleProductDto; import com.yuanchu.mom.exception.ErrorException; import com.yuanchu.mom.mapper.*; import com.yuanchu.mom.pojo.*; import com.yuanchu.mom.service.InsOrderPlanService; import com.yuanchu.mom.service.InsOrderService; import com.yuanchu.mom.service.StandardTemplateService; import com.yuanchu.mom.utils.GiveCode; import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.vo.InsOrderPlanVO; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ResourceUtils; import javax.annotation.Resource; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -36,24 +45,34 @@ * æ£éªä»»å¡-ä¸å¡å®ç°å± */ @Service @AllArgsConstructor //@AllArgsConstructor public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService { @Resource private InsSampleMapper insSampleMapper; @Resource private InsSampleUserMapper insSampleUserMapper; @Resource private GetLook getLook; @Resource private InsOrderMapper insOrderMapper; @Resource private InsOrderService insOrderService; @Resource private StandardTemplateService standardTemplateService; @Resource private InsOrderStateMapper insOrderStateMapper; @Resource private InsProductMapper insProductMapper; @Value("${wordUrl}") private String wordUrl; @Resource private GiveCode giveCode; @Resource private InsReportMapper insReportMapper; @Override public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { @@ -162,22 +181,36 @@ insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, num).set(InsOrderState::getVerifyTell, tell).set(InsOrderState::getVerifyUser, getLook.selectPowerByMethodAndUserId(null).get("userId"))); List<InsOrderState> insOrderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, orderId)); long count = insOrderStates.stream().filter(a -> a.getInsState() == 5).count(); if (count == insOrderStates.size()) { XWPFTemplate template = XWPFTemplate.compile("template.docx").render( if (count == insOrderStates.size() && num == 5) { InsOrder insOrder = insOrderMapper.selectById(orderId); Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId()); List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); samples.forEach(System.out::println); InsReport insReport = new InsReport(); insReport.setCode(giveCode.giveCode("JCZX/TX-", "ins_report", "-", "yyMMdd")); insReport.setInsOrderId(orderId); String url; try { url = ResourceUtils.getURL("classpath:static/report-template.docx").getPath(); } catch (FileNotFoundException e) { throw new ErrorException("æ¾ä¸å°æ¨¡æ¿æä»¶"); } XWPFTemplate template = XWPFTemplate.compile(url).render( new HashMap<String, Object>() {{ put("title", "Hi, poi-tl Word模æ¿å¼æ"); put("order", insOrder); put("report", insReport); put("user", user); put("samples", samples); put("sampleSize", samples.size() + samples.get(0).getUnit()); }}); try { template.writeAndClose(new FileOutputStream("output.docx")); String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; template.writeAndClose(new FileOutputStream(wordUrl + "/" + name)); insReport.setUrl("/word/"+ name); insReportMapper.insert(insReport); } catch (IOException e) { throw new RuntimeException(e); } List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); insSamples.forEach(a -> { System.out.println(a); List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, a.getId())); insProducts.forEach(System.out::println); }); } return 1; } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -1,19 +1,28 @@ package com.yuanchu.mom.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; import com.yuanchu.mom.dto.InsOrderPlanDTO; import com.yuanchu.mom.dto.ReportPageDto; import com.yuanchu.mom.dto.SampleOrderDto; import com.yuanchu.mom.exception.ErrorException; import com.yuanchu.mom.pojo.InsReport; import com.yuanchu.mom.service.InsReportService; import com.yuanchu.mom.mapper.InsReportMapper; import com.yuanchu.mom.utils.QueryWrappers; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -23,13 +32,17 @@ * @createDate 2024-03-17 22:10:02 */ @Service @AllArgsConstructor public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> implements InsReportService{ @Resource private GetLook getLook; @Resource private InsReportMapper insReportMapper; @Value("${wordUrl}") private String wordUrl; @Override public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) { @@ -40,6 +53,18 @@ map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto))); return map; } @Override public String wordToHtml(String path) { try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { Document document = new Document(); document.loadFromFile(path.replace("/word", wordUrl)); document.saveToFile(outputStream, FileFormat.Html); return outputStream.toString(); } catch (Exception e) { throw new ErrorException("转æ¢å¤±è´¥"); } } } inspect-server/src/main/resources/mapper/InsProductMapper.xml
@@ -46,4 +46,7 @@ left join ins_product ip on isa.id = ip.ins_sample_id where io.id = #{orderId} </select> <select id="selectUserById" resultType="java.util.Map"> select name,company,phone,address from user where id = #{userId} </select> </mapper> inspect-server/src/main/resources/static/report-template.docxBinary files differ
system-run/src/main/resources/application-dev.yml
@@ -18,10 +18,12 @@ # ç §çåå¨è·¯å¾+++++++++++++++++++++++++++è¿ç»´éè¦é ç½®+++++++++++++++++++++++++++ file: path: D:\Download path: D:\é¡¹ç®æä»¶åå¨\image # ä¸ä¼ æä»¶å è®¸çæ©å±å allowed: png,jpg,jpeg,gif wordUrl: D:\é¡¹ç®æä»¶åå¨\word mybatis-plus: type-aliases-package: com.yuanchu.mom.pojo mapper-locations: classpath*:/mapper/*.xml system-run/src/main/resources/application.yml
@@ -26,4 +26,4 @@ okhttp: enabled: true # å¼å¯ okhttp outPath: D:/Download/ outPath: D:\é¡¹ç®æä»¶åå¨\image wordToHtml.html
¶Ô±ÈÐÂÎļþ @@ -0,0 +1 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /><title></title><link href="wordToHtml_styles.css" type="text/css" rel="stylesheet"/></head><body /></html> wordToHtml_styles.css
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,2 @@ body{ font-family:'Times New Roman'; font-size:1em; } ul, ol{ margin-top: 0; margin-bottom: 0; }