| | |
| | | import com.deepoove.poi.config.ConfigureBuilder; |
| | | import com.deepoove.poi.data.*; |
| | | import com.deepoove.poi.data.style.*; |
| | | import com.deepoove.poi.data.style.Style; |
| | | import com.deepoove.poi.util.TableTools; |
| | | import com.yuanchu.mom.dto.InsReportDto1; |
| | | import com.yuanchu.mom.dto.InsReportDto2; |
| | | import com.yuanchu.mom.dto.SampleProductDto; |
| | | import com.spire.doc.FileFormat; |
| | | import com.yuanchu.mom.dto.*; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.vo.InsProductResult2VO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.openxml4j.util.ZipSecureFile; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; |
| | | import org.docx4j.XmlUtils; |
| | | import org.docx4j.jaxb.Context; |
| | | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
| | | import org.docx4j.wml.*; |
| | | import org.docx4j.wml.STBrType; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.bind.JAXBElement; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class WordUtils { |
| | | |
| | |
| | | |
| | | @Resource |
| | | StandardMethodListMapper standardMethodListMapper; |
| | | |
| | | @Value("${twoCode}") |
| | | private String twoCode; |
| | | |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | |
| | | if (inspectionItemSubclass.contains("互调")) { |
| | | aa += (angles + 1) * portRow * often; |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | if (inspectionItemSubclass.contains("电压驻波比")) { |
| | | aa += (angles + 1) * portRow; |
| | | } |
| | |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | if (i == 0) { |
| | | if (i == 1) { |
| | | //第一行 |
| | | textRenderData.setText("频段:" + s + "∑0" + lable); |
| | | renderData.add(textRenderData); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } |
| | | else { |
| | | if (insOrderState.getVersion() == 1) { |
| | | //非电调版本(简单版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= 2 * portRow) { |
| | |
| | | textRenderData.setText("不判定"); |
| | | } |
| | | } else { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | |
| | | } else if (j == 4) { |
| | | //第五列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("角度"); |
| | | textRenderData.setText("频段"); |
| | | } else { |
| | | textRenderData.setText(result2s.get(0).getAngle().split(",")[(i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 2) % (angles + 1)]); |
| | | } |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | if (products.get(0).getInsResult() == 1) { |
| | | textRenderData.setText("合格∑8" + index + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) + (angles - 1)) / (angles + 1) - 1)); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == bb - 1) { |
| | | } |
| | | else if (j == bb - 1) { |
| | | //最后一列 |
| | | if (i % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - cc) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (dd == 0 ? cc : dd)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | //第五列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | //角度 |
| | | textRenderData.setText("角度"); |
| | | textRenderData.setText("频段"); |
| | | } else { |
| | | //值 |
| | | textRenderData.setText(result2s.get(0).getAngle().split(",")[(i + (angles - 1)) % (angles + 1)]); |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | int k = (angles + 1) * portRow2; |
| | | int rr = qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq; |
| | | if (i > rr && i <= rr + k) { |
| | | ss = (rr + k) ; |
| | | ss = (rr + k); |
| | | if (itemSet.add("最大相位偏差")) { |
| | | index.getAndIncrement(); |
| | | } |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - rr) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | int length = result2s.get(0).getPort().split(",").length; |
| | | int portRow2 = (length % 8 == 0 ? length / 8 : length / 8 + 1); |
| | | int k = (angles + 1) * portRow2; |
| | | int rr =ss==0?( qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq) : ss; |
| | | int rr = ss == 0 ? (qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq) : ss; |
| | | if (i > ss) { |
| | | if (itemSet.add("相位绝对值")) { |
| | | index.getAndIncrement(); |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - ss) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | |
| | | //生成总报告 |
| | | public void generateReport(Integer orderId, InsReportDto1 insReportDto1) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | //委托部门 departLims |
| | | String departLims = userMapper.selectDepartLims(insOrder.getPrepareUser()); |
| | | SampleProductDto insSample = insSampleMapper.selectSampleProductListByOrderId(insReportDto1.getSampleId()); |
| | | String sampleCode = insSample.getSampleCode(); |
| | | SampleProductDto s = insSample; |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, insSample.getId()) |
| | | .eq(InsProduct::getState, 1)); |
| | | /*首页*/ |
| | | //产品名称 |
| | | String sampleName = insSample.getSample(); |
| | | //型号规格 |
| | | int indexOf = s.getModel().indexOf("-"); |
| | | String models = (indexOf!=-1?s.getModel().substring(indexOf + 1):s.getModel()); |
| | | //委托单位 |
| | | Custom custom = customMapper.selectById(insOrder.getCompanyId()); |
| | | //报告发布日期 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | //报告编号 |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(giveCode.giveCode("TXJC-", "ins_report", "-", "yyMMdd")); |
| | | insReport.setInsSampleId(insSample.getId()); |
| | | insReport.setInsOrderId(orderId); |
| | | Set<String> standardMethod = new HashSet<>(); |
| | | Set<String> deviceSet = new HashSet<>(); |
| | | Set<String> models = new HashSet<>(); |
| | | |
| | | /*检测报告描述*/ |
| | | //样品名称,型号规格,时间按照首页的来,order里面的信息有insOrder |
| | | //委托人和电话字段判断 |
| | | if (ObjectUtils.isEmpty(insOrder.getPrepareUser())) { |
| | | insOrder.setPrepareUser("/"); |
| | | } |
| | | if (ObjectUtils.isEmpty(insOrder.getPhone())) { |
| | | insOrder.setPhone("/"); |
| | | } |
| | | //委托部门 |
| | | String departLims = userMapper.selectDepartLims(insOrder.getPrepareUser()); |
| | | //样品编号 |
| | | String sampleCode = insSample.getSampleCode(); |
| | | //检测依据 |
| | | Set<String> standardMethod = new HashSet<>(); |
| | | standardMethod.addAll(insProducts.stream() |
| | | .map(insProduct -> { |
| | | String standardMethodName = standardMethodListMapper.getStandardMethodName(insProduct.getMethodS()); |
| | | return insProduct.getMethodS()+" "+standardMethodName; |
| | | }).distinct().collect(Collectors.toList())); |
| | | StringBuilder standardMethod2 = new StringBuilder(); |
| | | for (String s1 : standardMethod) { |
| | | standardMethod2.append(";\n").append(s1); |
| | | } |
| | | standardMethod2.replace(0, 1, ""); |
| | | //检测结论 |
| | | AtomicReference<Integer> productSize = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize1 = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize2 = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize3 = new AtomicReference<>(0); |
| | | String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; |
| | | SampleProductDto s = insSample; |
| | | models.add(s.getModel()); |
| | | standardMethod.addAll(standardMethodListMapper.selectList(Wrappers.<StandardMethodList>lambdaQuery() |
| | | .in(StandardMethodList::getId, Arrays.stream(s.getStandardMethodListId().replaceAll("[\\[\\]]", "").split(",")) |
| | | .map(String::trim).map(Integer::parseInt).collect(Collectors.toList()))).stream().map(aa -> { |
| | | return aa.getCode() + " " + aa.getName(); |
| | | }).distinct().collect(Collectors.toList())); |
| | | //总数 |
| | | Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId())); |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | //不判定 |
| | | Long productCount1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 3)); |
| | | // productSize1.set(productSize1.get() + Integer.parseInt(productCount1 + "")); |
| | | productSize1.set(productSize1.get() + Integer.parseInt(0 + "")); |
| | | long productCount = insProducts.size(); |
| | | //不合格 |
| | | Long productCount2 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 0)); |
| | | productSize2.set(productSize2.get() + Integer.parseInt(productCount2 + "")); |
| | | //合格 |
| | | Long productCount3 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 1)); |
| | | // productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); |
| | | productSize3.set(productSize3.get() + Integer.parseInt(productCount3+productCount1 + "")); |
| | | //将项目按照站点进行分类 |
| | | Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getSonLaboratory)); |
| | | // 创建一个 Map 将站点和项目ID的映射关系 |
| | | Map<String, Set<Integer>> labToDeviceMap = new HashMap<>(); |
| | | // 获取所有站点的项目ID 列表 |
| | | for (Map.Entry<String, List<InsProduct>> entry : listMap.entrySet()) { |
| | | Set<Integer> productIds = entry.getValue().stream() |
| | | .map(InsProduct::getId) |
| | | .collect(Collectors.toSet()); |
| | | labToDeviceMap.put(entry.getKey(), productIds); |
| | | } |
| | | for (InsReportDto2 insReportDto2 : insReportDto1.getInsReportDto2s()) { |
| | | String laboratory = insReportDto2.getLaboratory(); |
| | | if (!labToDeviceMap.containsKey(laboratory)) { |
| | | continue; |
| | | long productCount2 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 0).count(); |
| | | //合格=(不判定+合格) |
| | | long productCount1 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 3).count(); |
| | | long productCount3 = productCount1 + insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 1).count(); |
| | | //判断是否有辐射项目 |
| | | List<InsProduct> fusheProducts = insProducts.stream().filter(insProduct -> insProduct.getInspectionItem().equals("辐射试验")).collect(Collectors.toList()); |
| | | if (fusheProducts.size() > 0) { |
| | | for (InsProduct fusheProduct : fusheProducts) { |
| | | List<Long> vValues = new ArrayList<>(); |
| | | String insValue = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() |
| | | .eq(InsProductResult::getInsProductId, fusheProduct.getId())).get(0).getInsValue(); |
| | | Pattern pattern = Pattern.compile("\"v\":\"(\\d+)\""); |
| | | Matcher matcher = pattern.matcher(insValue); |
| | | while (matcher.find()) { |
| | | vValues.add(Long.parseLong(matcher.group(1))); |
| | | } |
| | | if (vValues.size() > 0) { |
| | | //不合格 |
| | | if (vValues.get(1) != 0) { |
| | | productCount2 = productCount2 + vValues.get(1); |
| | | } |
| | | //合格 |
| | | if (vValues.get(0) != 0) { |
| | | if (fusheProduct.getInsResult() == 1) { |
| | | productCount3 = productCount3 + vValues.get(0); |
| | | } |
| | | } |
| | | // 判定是否减掉辐射检验项本身 |
| | | if (fusheProduct.getInsResult() == 1) { |
| | | productCount3 = productCount3 - 1; |
| | | }else if(fusheProduct.getInsResult() == 0){ |
| | | productCount2 = productCount2 - 1; |
| | | } |
| | | //总数=项目总数-辐射项目数量+辐射具体的(合格+不合格)数量 |
| | | productCount = productCount - 1 + vValues.stream().mapToLong(Long::longValue).sum(); |
| | | } |
| | | } |
| | | Set<Integer> productIds = labToDeviceMap.get(laboratory); |
| | | Integer num = insReportDto2.getNum(); |
| | | //普通试验结果表 |
| | | List<InsProductResult> insProductResults = insProductResultMapper.selectList( |
| | | Wrappers.<InsProductResult>lambdaQuery() |
| | | .eq(InsProductResult::getNum, num) |
| | | .in(InsProductResult::getInsProductId, productIds)); |
| | | for (InsProductResult insProductResult : insProductResults) { |
| | | List<JSONObject> jsonObjects = JSON.parseArray(insProductResult.getEquipValue(), JSONObject.class); |
| | | } |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | productSize2.set(productSize2.get() + Integer.parseInt(productCount2 + "")); |
| | | productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); |
| | | |
| | | /*检验情况一览表*/ |
| | | List<InsProductWordDto> insProductList = new ArrayList<>(); |
| | | int index1=1; |
| | | for (InsProduct insPro : insProducts) { |
| | | InsProductWordDto insProductWordDto = new InsProductWordDto(); |
| | | insProductWordDto.setIndex(index1+"");//序号 |
| | | insProductWordDto.setTerm(insPro.getInspectionItem()+"-"+insPro.getInspectionItemSubclass());//检验项目 |
| | | if (ObjectUtils.isNotNull(insPro.getInsResult()) && insPro.getInsResult()==0) { |
| | | insProductWordDto.setResult("不合格");//结论 |
| | | } else { |
| | | insProductWordDto.setResult("合格");//结论 |
| | | } |
| | | insProductList.add(insProductWordDto); |
| | | index1++; |
| | | } |
| | | |
| | | /*检测结果*/ |
| | | //获取所有检验的站点信息 |
| | | List<String> strings = insReportDto1.getInsReportDto2s().stream() |
| | | .map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList()); |
| | | //电路表格 |
| | | List<Map<String, Object>> tables2 = new ArrayList<>(); |
| | | if (strings.contains("电路试验")) { |
| | | /*勾选的电路试验表*/ |
| | | List<InsReportDto2> dto2s = insReportDto1.getInsReportDto2s().stream().filter(insReportDto2 -> insReportDto2.getLaboratory().equals("电路试验")).collect(Collectors.toList()); |
| | | for (InsReportDto2 insReportDto2 : dto2s) { |
| | | InsOrderUser insOrderUser = insOrderUserMapper.selectById(insReportDto2.getInsOrderUsersId()); |
| | | InsOrderState orderState = insOrderStateMapper.selectById(insOrderUser.getInsOrderStateId()); |
| | | orderState.setNum(insOrderUser.getNum()); |
| | | if (!insOrder.getSampleType().equals("无源器件")) { |
| | | getWord1(insOrderUser.getTerm(), orderState, tables2); |
| | | } else { |
| | | getWord2(insOrderUser.getTerm(), orderState, tables2); |
| | | } |
| | | } |
| | | } |
| | | //辐射表格 |
| | | List<Map<String, Object>> tables3 = new ArrayList<>(); |
| | | List<InsOrderFile> insOrderDocFiles = new ArrayList<>();; // 暂存需要合并表单到生成word文件的docx文件 |
| | | // 统计辐射实验表数量 |
| | | int radiationReportNum = 0; |
| | | if (strings.contains("近场") || strings.contains("远场")) { |
| | | /*辐射的试验表*/ |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | .eq(InsOrderFile::getInsOrderId, orderId) |
| | | .eq(InsOrderFile::getInsSampleId, insReportDto1.getSampleId()) |
| | | .like(InsOrderFile::getFileName, "解析的辐射站点报告") |
| | | .and(wrapper -> wrapper |
| | | .eq(InsOrderFile::getSonLaboratory, "远场") |
| | | .or() |
| | | .eq(InsOrderFile::getSonLaboratory, "近场") |
| | | )); |
| | | insOrderDocFiles.addAll(insOrderFiles); |
| | | radiationReportNum = insOrderFiles.size(); |
| | | // if (insOrderFiles.size() > 0) { |
| | | // int aa = 0; |
| | | // for (InsOrderFile insOrderFile : insOrderFiles) { |
| | | // try { |
| | | // XWPFDocument circuitParamsDoc = new XWPFDocument(new FileInputStream(wordUrl + "/" + insOrderFile.getFileUrl())); |
| | | // // 遍历电路参数文件的所有元素,段落和表格 |
| | | // for (IBodyElement element : circuitParamsDoc.getBodyElements()) { |
| | | // Map<String, Object> table3 = new HashMap<>(); |
| | | // TableRenderData tableData = new TableRenderData(); |
| | | // List<RowRenderData> rows = new ArrayList<>(); |
| | | // if (element instanceof XWPFTable) { |
| | | // aa += 1; |
| | | // XWPFTable tab = (XWPFTable) element; |
| | | // List<XWPFTableRow> row = tab.getRows(); |
| | | // for (int i = 0; i < row.size(); i++) { |
| | | // RowRenderData rowRenderData = new RowRenderData(); |
| | | // List<CellRenderData> cells = new ArrayList<>(); |
| | | // List<XWPFTableCell> cell = row.get(i).getTableCells(); |
| | | // for (int j = 0; j < cell.size(); j++) { |
| | | // CellRenderData cellRenderData = new CellRenderData(); |
| | | // List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | // ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | // ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | // paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | // paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | // List<RenderData> renderData = new ArrayList<>(); |
| | | // TextRenderData textRenderData = new TextRenderData(); |
| | | // Style style = new Style(); |
| | | // style.setFontFamily("宋体"); |
| | | // style.setColor("000000"); |
| | | // textRenderData.setStyle(style); |
| | | // CTTcPr tcPr = cell.get(j).getCTTc().getTcPr(); |
| | | // if (tcPr != null) { |
| | | // //合并列 |
| | | // CTHMerge hMerge = tcPr.getHMerge(); |
| | | // if (ObjectUtils.isNotEmpty(hMerge)) { |
| | | // if (STMerge.RESTART.equals(hMerge.getVal()) || STMerge.CONTINUE.equals(hMerge.getVal())) { |
| | | // int index = j; |
| | | // String text = null; |
| | | // while (text == null || text.equals("")) { |
| | | // if (index < 0) { |
| | | // text = "/"; |
| | | // } |
| | | // text = cell.get(index).getText(); |
| | | // index--; |
| | | // } |
| | | // textRenderData.setText(text + "∑88" + aa + i); |
| | | // } |
| | | // } |
| | | // //合并行 |
| | | // CTVMerge vMerge = tcPr.getVMerge(); |
| | | // if (ObjectUtils.isNotEmpty(vMerge)) { |
| | | // if (STMerge.RESTART.equals(vMerge.getVal()) || STMerge.CONTINUE.equals(vMerge.getVal())) { |
| | | // int index = i; |
| | | // String text = null; |
| | | // while (text == null || text.equals("")) { |
| | | // if (index < 0) { |
| | | // text = "/"; |
| | | // break; |
| | | // } |
| | | // text = row.get(index).getCell(j).getText(); |
| | | // index--; |
| | | // } |
| | | // if (text.equals("合格") || text.equals("不合格")) { |
| | | // textRenderData.setText(text + "∑25" + aa + j); |
| | | // } else { |
| | | // textRenderData.setText(text + "∑22" + aa + j); |
| | | // } |
| | | // } |
| | | // } |
| | | // } else { |
| | | // textRenderData.setText(cell.get(j).getText()); |
| | | // } |
| | | // renderData.add(textRenderData); |
| | | // paragraphRenderData.setContents(renderData); |
| | | // paragraphRenderDataList.add(paragraphRenderData); |
| | | // cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | // cells.add(cellRenderData); |
| | | // } |
| | | // rowRenderData.setCells(cells); |
| | | // rows.add(rowRenderData); |
| | | // } |
| | | // tableData.setRows(rows); |
| | | // table3.put("table3", tableData); |
| | | // tables3.add(table3); |
| | | // } |
| | | // } |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | //辐射的标题 |
| | | String title3 = ""; |
| | | if (radiationReportNum > 0) { |
| | | title3 = "辐射方向图参数"; |
| | | } |
| | | //环境表格 |
| | | List<Map<String, Object>> tables4 = new ArrayList<>(); |
| | | //创建环境试验条件表2*(项目数+1) |
| | | List<InsProduct> products = insSample.getInsProduct().stream() |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("电路试验")) |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("辐射试验")) |
| | | .map(insProduct -> { |
| | | InsProduct product = new InsProduct(); |
| | | product.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); |
| | | product.setTell(insProduct.getTell()); |
| | | return product; |
| | | }).distinct().collect(Collectors.toList()); |
| | | if (products.size()>0) { |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | //行数 |
| | | for (int i = 0; i < products.size() + 1; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //列数 |
| | | for (int j = 0; j < 3; j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | CellStyle cellStyle = new CellStyle(); |
| | | cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); |
| | | cellRenderData.setCellStyle(cellStyle); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | if (i == 0) { |
| | | //第一行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText("项目"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("试验要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | textRenderData.setText("实验结果"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else { |
| | | //其余行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText(products.get(i - 1).getInspectionItemSubclass()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText(products.get(i - 1).getTell()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | //获取检验项目和结论 |
| | | InsProduct insProduct = products.get(i - 1); |
| | | String shiyanjieguo = "无异常"; |
| | | if (ObjectUtils.isNotNull(insProduct.getInsResult())) { |
| | | shiyanjieguo = insProduct.getInsResult() == 0 ? "不合格" : "无异常"; |
| | | } |
| | | textRenderData.setText("经过" + insProduct.getInspectionItemSubclass() + "之后,样品" + shiyanjieguo + "。"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | if (rowRenderData.getCells().size() != 0) { |
| | | rows.add(rowRenderData); |
| | | } |
| | | } |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | int countSize = tableRenderData.getRows().get(0).getCells().size(); |
| | | for (RowRenderData row : tableRenderData.getRows()) { |
| | | if (row.getCells().size() != countSize) { |
| | | throw new ErrorException("每行单元格不相等"); |
| | | } |
| | | } |
| | | TableStyle tableStyle = new TableStyle(); |
| | | tableStyle.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.THICK); |
| | | borderStyle.setSize(4); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | Map<String, Object> table4 = new HashMap<>(); |
| | | table4.put("table4", tableRenderData); |
| | | tables4.add(table4); |
| | | } |
| | | |
| | | /*检验样品信息*/ |
| | | //样品照片 |
| | | List<UrlListDto> urlList = new ArrayList<>(); |
| | | //获取附件图片类型 |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | .eq(InsOrderFile::getType, 1) |
| | | .eq(InsOrderFile::getInsSampleId,insReportDto1.getSampleId()) |
| | | .eq(InsOrderFile::getInsOrderId, orderId)); |
| | | if (CollectionUtils.isNotEmpty(insOrderFiles)) { |
| | | UrlListDto urlListDto = new UrlListDto(); |
| | | for (int i = 0; i < insOrderFiles.size(); i++) { |
| | | if (i % 2 == 0) { |
| | | urlListDto = new UrlListDto(); |
| | | urlListDto.setImageOne(Pictures.ofLocal(imgUrl + "/" + insOrderFiles.get(i).getFileUrl()).create()); |
| | | if (i == insOrderFiles.size() - 1) { |
| | | urlList.add(urlListDto); |
| | | } |
| | | } else { |
| | | urlListDto.setImageTwo(Pictures.ofLocal(imgUrl + "/" + insOrderFiles.get(i).getFileUrl()).create()); |
| | | urlList.add(urlListDto); |
| | | } |
| | | |
| | | } |
| | | } |
| | | //样品编号参照上述sampleCode |
| | | |
| | | |
| | | /*检测人员信息*/ |
| | | List<InsUserDto> insUsers = new ArrayList<>(); |
| | | //查询每个站点的检验人员与复核人员 |
| | | List<InsSampleUser> insSampleUsers = insSampleUserMapper.selectList(Wrappers.<InsSampleUser>lambdaQuery() |
| | | .eq(InsSampleUser::getInsSampleId, insReportDto1.getSampleId())); |
| | | //根据站点进行分类 |
| | | Map<String, List<InsSampleUser>> listMap = insSampleUsers.stream().collect(Collectors.groupingBy(InsSampleUser::getSonLaboratory)); |
| | | int index2=1; |
| | | for (Map.Entry<String, List<InsSampleUser>> entry : listMap.entrySet()) { |
| | | InsUserDto insUserDto = new InsUserDto(); |
| | | insUserDto.setIndex(index2+"");//序号 |
| | | insUserDto.setInsProduct(entry.getKey());//项目 |
| | | List<InsSampleUser> insUserList = entry.getValue().stream().filter(insSampleUser -> insSampleUser.getState() == 0).collect(Collectors.toList());//检验人 |
| | | String insUser = insUserList.stream().map(insSampleUser -> { |
| | | User user = userMapper.selectById(insSampleUser.getUserId()); |
| | | return user.getName(); |
| | | }).distinct().collect(Collectors.joining(",")); |
| | | insUserDto.setInsUser(insUser);//测试人员 |
| | | List<InsSampleUser> checkUserList = entry.getValue().stream().filter(insSampleUser -> insSampleUser.getState() == 1).collect(Collectors.toList());//复核人 |
| | | String checkUser = checkUserList.stream().map(insSampleUser -> { |
| | | User user = userMapper.selectById(insSampleUser.getUserId()); |
| | | return user.getName(); |
| | | }).distinct().collect(Collectors.joining(",")); |
| | | insUserDto.setCheckUser(checkUser);//审核人员 |
| | | insUsers.add(insUserDto); |
| | | index2++; |
| | | } |
| | | |
| | | /*测试仪表*/ |
| | | Set<String> deviceSet = new HashSet<>(); |
| | | //查询所有项目的设备 |
| | | List<Integer> productIds = insProducts.stream().map(InsProduct::getId).collect(Collectors.toList()); |
| | | //普通 |
| | | List<InsProductResult> results = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() |
| | | .in(InsProductResult::getInsProductId, productIds)); |
| | | if (results.size()>0){ |
| | | for (InsProductResult result : results) { |
| | | List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class); |
| | | if (ObjectUtils.isNotEmpty(jsonObjects)) { |
| | | for (JSONObject jsonObject : jsonObjects) { |
| | | String value = jsonObject.getString("v"); |
| | |
| | | } |
| | | } |
| | | } |
| | | //电路试验结果表 |
| | | List<InsProductResult2> insProductResult2s = insProductResult2Mapper.selectList( |
| | | Wrappers.<InsProductResult2>lambdaQuery() |
| | | .eq(InsProductResult2::getNum, num) |
| | | .in(InsProductResult2::getInsProductId, productIds)); |
| | | for (InsProductResult2 result2 : insProductResult2s) { |
| | | } |
| | | //电路 |
| | | List<InsProductResult2> result2s = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery() |
| | | .in(InsProductResult2::getInsProductId, productIds)); |
| | | if (result2s.size()>0){ |
| | | for (InsProductResult2 result2 : result2s) { |
| | | String equipValue = result2.getEquipValue(); |
| | | if (equipValue != null && !equipValue.isEmpty()) { |
| | | deviceSet.add(equipValue); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /*检验情况一览表*/ |
| | | List<Map<String, String>> tables = new ArrayList<>(); |
| | | List<Map<String, Object>> tables2 = new ArrayList<>(); |
| | | List<Map<String, Object>> tables3 = new ArrayList<>(); |
| | | List<Map<String, Object>> tables4 = new ArrayList<>(); |
| | | Integer indexs = 1; |
| | | //判断是否有电路试验,环境试验 |
| | | List<String> strings = insReportDto1.getInsReportDto2s().stream().map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList()); |
| | | if (strings.contains("近场") || strings.contains("远场")) { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | indexs += 1; |
| | | table.put("term", "辐射方向图参数"); |
| | | table.put("result", "不判定"); |
| | | tables.add(table); |
| | | /*辐射的试验表*/ |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | .eq(InsOrderFile::getInsOrderId, orderId) |
| | | .eq(InsOrderFile::getInsSampleId, insReportDto1.getSampleId()) |
| | | .like(InsOrderFile::getFileName, "解析的辐射站点报告") |
| | | .and(wrapper -> wrapper |
| | | .eq(InsOrderFile::getSonLaboratory, "远场") |
| | | .or() |
| | | .eq(InsOrderFile::getSonLaboratory, "近场") |
| | | )); |
| | | if (insOrderFiles.size() > 0) { |
| | | int aa = 0; |
| | | for (InsOrderFile insOrderFile : insOrderFiles) { |
| | | try { |
| | | XWPFDocument circuitParamsDoc = new XWPFDocument(new FileInputStream(wordUrl + "/" + insOrderFile.getFileUrl())); |
| | | // 遍历电路参数文件的所有元素,段落和表格 |
| | | for (IBodyElement element : circuitParamsDoc.getBodyElements()) { |
| | | Map<String, Object> table3 = new HashMap<>(); |
| | | TableRenderData tableData = new TableRenderData(); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | if (element instanceof XWPFTable) { |
| | | aa += 1; |
| | | XWPFTable tab = (XWPFTable) element; |
| | | List<XWPFTableRow> row = tab.getRows(); |
| | | for (int i = 0; i < row.size(); i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | List<XWPFTableCell> cell = row.get(i).getTableCells(); |
| | | for (int j = 0; j < cell.size(); j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | CTTcPr tcPr = cell.get(j).getCTTc().getTcPr(); |
| | | if (tcPr != null) { |
| | | //合并列 |
| | | CTHMerge hMerge = tcPr.getHMerge(); |
| | | if (ObjectUtils.isNotEmpty(hMerge)) { |
| | | if (STMerge.RESTART.equals(hMerge.getVal()) || STMerge.CONTINUE.equals(hMerge.getVal())) { |
| | | int index = j; |
| | | String text = null; |
| | | while (text == null || text.equals("")) { |
| | | if (index < 0) { |
| | | text = "/"; |
| | | } |
| | | text = cell.get(index).getText(); |
| | | index--; |
| | | } |
| | | textRenderData.setText(text + "∑88" + aa + i); |
| | | } |
| | | } |
| | | //合并行 |
| | | CTVMerge vMerge = tcPr.getVMerge(); |
| | | if (ObjectUtils.isNotEmpty(vMerge)) { |
| | | if (STMerge.RESTART.equals(vMerge.getVal()) || STMerge.CONTINUE.equals(vMerge.getVal())) { |
| | | int index = i; |
| | | String text = null; |
| | | while (text == null || text.equals("")) { |
| | | if (index < 0) { |
| | | text = "/"; |
| | | break; |
| | | } |
| | | text = row.get(index).getCell(j).getText(); |
| | | index--; |
| | | } |
| | | if (text.equals("合格") || text.equals("不合格")) { |
| | | textRenderData.setText(text + "∑25" + aa + j); |
| | | } else { |
| | | textRenderData.setText(text + "∑22" + aa + j); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | textRenderData.setText(cell.get(j).getText()); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | rows.add(rowRenderData); |
| | | } |
| | | tableData.setRows(rows); |
| | | table3.put("table3", tableData); |
| | | tables3.add(table3); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | List<DevListDto> devList = new ArrayList<>(); |
| | | if (deviceSet.size() != 0) { |
| | | devList = insOrderMapper.selectDeviceList(deviceSet); |
| | | } |
| | | if (strings.contains("电路试验")) { |
| | | strings.remove("电路试验"); |
| | | strings.remove("近场"); |
| | | strings.remove("远场"); |
| | | List<Integer> productIdes = insSample.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList()); |
| | | List<Integer> collect = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery() |
| | | .in(InsProductResult2::getInsProductId, productIdes)) |
| | | .stream().map(InsProductResult2::getResult).distinct().collect(Collectors.toList()); |
| | | //如果有环境试验 |
| | | if (strings.size() > 0) { |
| | | Map<String, String> table1 = new HashMap<>(); |
| | | table1.put("indexs", indexs + ""); |
| | | table1.put("term", "环境试验前电路参数"); |
| | | if (collect.contains(0)) { |
| | | table1.put("result", "不合格"); |
| | | } else { |
| | | table1.put("result", "合格"); |
| | | } |
| | | tables.add(table1); |
| | | indexs += 1; |
| | | |
| | | Map<String, String> table2 = new HashMap<>(); |
| | | table2.put("indexs", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("term", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("result", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | tables.add(table2); |
| | | |
| | | Map<String, String> table3 = new HashMap<>(); |
| | | table3.put("indexs", indexs + ""); |
| | | table3.put("term", "环境试验后电路参数"); |
| | | if (collect.contains(0)) { |
| | | table3.put("result", "不合格"); |
| | | } else { |
| | | table3.put("result", "合格"); |
| | | } |
| | | tables.add(table3); |
| | | indexs += 1; |
| | | |
| | | /*创建环境试验条件表2*(项目数+1)*/ |
| | | List<InsProduct> products = insSample.getInsProduct().stream() |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("电路试验")) |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("辐射试验")) |
| | | .map(insProduct -> { |
| | | InsProduct product = new InsProduct(); |
| | | product.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); |
| | | product.setTell(insProduct.getTell()); |
| | | return product; |
| | | }).distinct().collect(Collectors.toList()); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | //行数 |
| | | for (int i = 0; i < products.size() + 1; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //列数 |
| | | for (int j = 0; j < 2; j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | CellStyle cellStyle = new CellStyle(); |
| | | cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); |
| | | cellRenderData.setCellStyle(cellStyle); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | if (i == 0) { |
| | | //第一行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText("项目"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第二列 |
| | | textRenderData.setText("试验要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else { |
| | | //其余行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText(products.get(i - 1).getInspectionItemSubclass()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | textRenderData.setText(products.get(i - 1).getTell()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | if (rowRenderData.getCells().size() != 0) { |
| | | rows.add(rowRenderData); |
| | | } |
| | | } |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | int countSize = tableRenderData.getRows().get(0).getCells().size(); |
| | | for (RowRenderData row : tableRenderData.getRows()) { |
| | | if (row.getCells().size() != countSize) { |
| | | throw new ErrorException("每行单元格不相等"); |
| | | } |
| | | } |
| | | TableStyle tableStyle = new TableStyle(); |
| | | tableStyle.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.THICK); |
| | | borderStyle.setSize(4); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | Map<String, Object> table4 = new HashMap<>(); |
| | | table4.put("table4", tableRenderData); |
| | | tables4.add(table4); |
| | | } else { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | table.put("term", "电路参数"); |
| | | if (collect.contains(0)) { |
| | | table.put("result", "不合格"); |
| | | } else { |
| | | table.put("result", "合格"); |
| | | } |
| | | tables.add(table); |
| | | indexs += 1; |
| | | } |
| | | /*勾选的电路试验表*/ |
| | | for (InsReportDto2 insReportDto2 : insReportDto1.getInsReportDto2s()) { |
| | | InsOrderUser insOrderUser = insOrderUserMapper.selectById(insReportDto2.getInsOrderUsersId()); |
| | | InsOrderState orderState = insOrderStateMapper.selectById(insOrderUser.getInsOrderStateId()); |
| | | if (orderState.getLaboratory().equals("电路试验")) { |
| | | orderState.setNum(insOrderUser.getNum()); |
| | | if (!insOrder.getSampleType().equals("无源器件")) { |
| | | getWord1(insOrderUser.getTerm(), orderState, tables2); |
| | | } else { |
| | | getWord2(insOrderUser.getTerm(), orderState, tables2); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | //如果只有环境试验没有电路试验 |
| | | strings.remove("近场"); |
| | | strings.remove("远场"); |
| | | if (strings.size() > 0) { |
| | | Map<String, String> table2 = new HashMap<>(); |
| | | table2.put("indexs", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("term", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("result", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | tables.add(table2); |
| | | |
| | | /*创建环境试验条件表2*(项目数+1)*/ |
| | | List<InsProduct> products = insSample.getInsProduct().stream() |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("电路试验")) |
| | | .filter(insProduct -> !insProduct.getInspectionItem().equals("辐射试验")) |
| | | .map(insProduct -> { |
| | | InsProduct product = new InsProduct(); |
| | | product.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); |
| | | product.setTell(insProduct.getTell()); |
| | | return product; |
| | | }).distinct().collect(Collectors.toList()); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | //行数 |
| | | for (int i = 0; i < products.size() + 1; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //列数 |
| | | for (int j = 0; j < 2; j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | CellStyle cellStyle = new CellStyle(); |
| | | cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); |
| | | cellRenderData.setCellStyle(cellStyle); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | if (i == 0) { |
| | | //第一行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText("项目"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第二列 |
| | | textRenderData.setText("试验要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else { |
| | | //其余行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText(products.get(i - 1).getInspectionItemSubclass()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | textRenderData.setText(products.get(i - 1).getTell()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | if (rowRenderData.getCells().size() != 0) { |
| | | rows.add(rowRenderData); |
| | | } |
| | | } |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | int countSize = tableRenderData.getRows().get(0).getCells().size(); |
| | | for (RowRenderData row : tableRenderData.getRows()) { |
| | | if (row.getCells().size() != countSize) { |
| | | throw new ErrorException("每行单元格不相等"); |
| | | } |
| | | } |
| | | TableStyle tableStyle = new TableStyle(); |
| | | tableStyle.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.THICK); |
| | | borderStyle.setSize(4); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | Map<String, Object> table4 = new HashMap<>(); |
| | | table4.put("table4", tableRenderData); |
| | | tables4.add(table4); |
| | | } |
| | | } |
| | | /*生成报告*/ |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | StringBuilder standardMethod2 = new StringBuilder(); |
| | | for (String s1 : standardMethod) { |
| | | standardMethod2.append(";\n").append(s1); |
| | | } |
| | | standardMethod2.append(";\n").append("GB/T 9410-2008 《移动通信天线通用技术规范》"); |
| | | standardMethod2.replace(0, 1, ""); |
| | | List<Map<String, String>> deviceList = null; |
| | | if (deviceSet.size() != 0) { |
| | | deviceList = insOrderMapper.selectDeviceList(deviceSet); |
| | | } |
| | | Map<String, String> codeStr = new HashMap<>(); |
| | | codeStr.put("报告编号", insReport.getCode()); |
| | | codeStr.put("样品名称", insSample.getSample()); |
| | | codeStr.put("规格型号", insSample.getModel()); |
| | | codeStr.put("发放日期", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | String codePath; |
| | | try { |
| | | codePath = new MatrixToImageWriter().code(JackSonUtil.marshal(codeStr).replaceAll("\\{", "") |
| | | .replaceAll("}", "").replaceAll(",", "").replaceAll("\"", ""), twoCode); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | String modelStr = ""; |
| | | for (String model : models) { |
| | | modelStr += "," + model; |
| | | } |
| | | String finalModelStr = modelStr; |
| | | String sampleEn = insSampleMapper.getSampleEn(insOrder.getSample()); |
| | | String orderType = insOrderMapper.getEnumLabelByValue(insOrder.getOrderType()); |
| | | String formType = insOrderMapper.getEnumLabelByValue(insOrder.getFormType()); |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | List<Map<String, String>> finalDeviceList = deviceList; |
| | | List<Map<String, String>> sampleList = insSampleMapper.selectSampleList(orderId); |
| | | Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery() |
| | | .eq(InsSampleUser::getInsSampleId, insReportDto1.getSampleId()) |
| | | .eq(InsSampleUser::getState, 0) |
| | | .last("limit 1")).getUserId(); |
| | | String signatureUrl; |
| | | try { |
| | | signatureUrl = userMapper.selectById(userId).getSignatureUrl(); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("找不到检验人的签名"); |
| | | } |
| | | if (ObjectUtils.isEmpty(signatureUrl) || signatureUrl.equals("")) { |
| | | throw new ErrorException("找不到检验人的签名"); |
| | | } |
| | | Custom custom = customMapper.selectById(insOrder.getCompanyId()); |
| | | |
| | | /*获取附件图片类型*/ |
| | | List<Map<String, Object>> images = new ArrayList<>(); |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery().eq(InsOrderFile::getType, 1).eq(InsOrderFile::getInsOrderId, orderId)); |
| | | if (CollectionUtils.isNotEmpty(insOrderFiles)) { |
| | | insOrderFiles.forEach(insOrderFile -> { |
| | | Map<String, Object> image = new HashMap<>(); |
| | | PictureRenderData pictureRenderData = Pictures.ofLocal(imgUrl + "/" + insOrderFile.getFileUrl()).sizeInCm(17, 20).create(); |
| | | image.put("url", pictureRenderData); |
| | | image.put("report", insReport); |
| | | images.add(image); |
| | | }); |
| | | } |
| | | //委托人和电话字段判断 |
| | | if (ObjectUtils.isEmpty(insOrder.getPrepareUser())) { |
| | | insOrder.setPrepareUser("/"); |
| | | } |
| | | if (ObjectUtils.isEmpty(insOrder.getPhone())) { |
| | | insOrder.setPhone("/"); |
| | | } |
| | | //检验项目的环境 |
| | | InsProduct insProduct = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, insReportDto1.getSampleId())).get(0); |
| | | String environment = ""; |
| | | environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "℃ " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : ""); |
| | | String finalEnvironment = environment; |
| | | String title3 = ""; |
| | | if (tables3.size() > 0) { |
| | | title3 = "辐射方向图参数"; |
| | | } |
| | | Configure configure = Configure.builder() |
| | | .bind("insProductList", new HackLoopTableRenderPolicy()) |
| | | .bind("devList", new HackLoopTableRenderPolicy()) |
| | | .bind("insUsers", new HackLoopTableRenderPolicy()) |
| | | .bind("urlList", new HackLoopTableRenderPolicy()) |
| | | .build(); |
| | | List<DevListDto> finalDevList = devList; |
| | | String finalTitle = title3; |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("order", insOrder); |
| | | put("report", insReport); |
| | | put("departLims", departLims); |
| | | put("sampleCode", sampleCode); |
| | | put("environment", finalEnvironment); |
| | | put("custom", custom); |
| | | put("sampleSize", "1"); |
| | | put("standardMethod", (standardMethod2.toString().equals("null") ? "" : standardMethod2)); |
| | | put("deviceList", finalDeviceList); |
| | | put("tables", tables); |
| | | put("tables2", tables2); |
| | | put("title3", finalTitle); |
| | | put("tables3", tables3); |
| | | put("tables4", tables4); |
| | | put("sampleList", sampleList); |
| | | put("twoCode", Pictures.ofLocal(codePath).create()); |
| | | put("models", finalModelStr.replace(",", "")); |
| | | put("productSize", productSize); |
| | | put("productSize1", productSize1); |
| | | put("productSize2", productSize2); |
| | | put("productSize3", productSize3); |
| | | put("createTime", now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); |
| | | // put("createTimeEn", monthNames[now.getMonthValue() - 1] + " " + now.getDayOfMonth() + ", " + now.getYear()); |
| | | put("insTime", insOrder.getInsTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); |
| | | put("insTimeEn", monthNames[insOrder.getInsTime().getMonthValue() - 1] + " " + insOrder.getInsTime().getDayOfMonth() + ", " + insOrder.getInsTime().getYear()); |
| | | put("writeUrl", null); |
| | | put("insUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); |
| | | put("images", images); |
| | | put("examineUrl", null); |
| | | put("ratifyUrl", null); |
| | | put("sampleEn", sampleEn); |
| | | put("orderType", orderType); |
| | | put("getTime", insOrder.getExamineTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); |
| | | put("getTimeEn", monthNames[insOrder.getExamineTime().getMonthValue() - 1] + " " + insOrder.getExamineTime().getDayOfMonth() + ", " + insOrder.getExamineTime().getYear()); |
| | | put("seal1", null); |
| | | put("seal2", null); |
| | | put("formTypeCh", formType); |
| | | put("formTypeEn", insOrder.getFormType()); |
| | | put("sampleName", sampleName); //产品名称 |
| | | put("models",models); //型号规格 |
| | | put("custom", custom); //委托单位 |
| | | put("createTime", now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); //报告发布日期 |
| | | put("departLims", departLims); //委托部门 |
| | | put("sampleCode", sampleCode); //样品编号 |
| | | put("order", insOrder); //订单主体信息 |
| | | put("getTime", insOrder.getExamineTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); //来样日期 |
| | | put("insTime", insOrder.getInsTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); //检测日期 |
| | | put("standardMethod", (standardMethod2.toString().equals("null") ? "" : standardMethod2)); //检测依据 |
| | | put("productSize", productSize); //检测结论 |
| | | put("productSize2", productSize2); //检测结论 |
| | | put("productSize3", productSize3); //检测结论 |
| | | put("report", insReport); //报告编号 |
| | | put("insProductList", insProductList); //检验情况一览表 |
| | | put("tables2", tables2); //检测结果 |
| | | put("title3", finalTitle); //检测结果 |
| | | put("tables3", null); //检测结果 |
| | | put("tables4", tables4); //检测结果 |
| | | put("urlList", urlList); //样品照片 |
| | | put("insUsers", insUsers); //检测人员信息 |
| | | put("devList", finalDevList); //测试仪表 |
| | | put("writeUrl", null); //提交人 |
| | | put("examineUrl", null); //审核人 |
| | | put("ratifyUrl", null); //批准人 |
| | | put("seal1", null); //印章 |
| | | put("seal2", null); //印章 |
| | | }}); |
| | | try { |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | |
| | | FileInputStream stream = new FileInputStream(path); |
| | | XWPFDocument document = new XWPFDocument(stream); |
| | | List<XWPFTable> xwpfTables = document.getTables(); |
| | | for (int i = 1; i < xwpfTables.size() - (deviceList == null ? 1 : 2); i++) { |
| | | for (int i = 1; i < xwpfTables.size() - (devList == null ? 1 : 2); i++) { |
| | | Set<String> set1 = new HashSet<>(); |
| | | Map<String, Map<String, Integer>> maps = new HashMap<>(); |
| | | for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) { |
| | |
| | | FileInputStream stream1 = new FileInputStream(path); |
| | | XWPFDocument document1 = new XWPFDocument(stream1); |
| | | List<XWPFTable> xwpfTables1 = document1.getTables(); |
| | | for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) { |
| | | for (int i = 1; i < xwpfTables1.size() - (devList == null ? 1 : 2); i++) { |
| | | for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) { |
| | | for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) { |
| | | if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) { |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 更新表单 |
| | | try { |
| | | WordprocessingMLPackage targetDoc = WordprocessingMLPackage.load(new File(path)); |
| | | List<Object> targetContent = targetDoc.getMainDocumentPart().getContent(); |
| | | int targetIndex = findFirstTargetIndex(targetDoc, title3); |
| | | if (targetIndex != -1) { |
| | | List<Object> forms = new ArrayList<>(); |
| | | for (InsOrderFile insOrderFile : insOrderDocFiles) { |
| | | // 加载源文档并提取表单内容(假设为表格) |
| | | WordprocessingMLPackage sourceDoc = WordprocessingMLPackage.load(new File(wordUrl + "/" + insOrderFile.getFileUrl())); |
| | | List<Object> sourceContent = sourceDoc.getMainDocumentPart().getContent(); |
| | | for (Object obj : sourceContent) { |
| | | if (obj instanceof JAXBElement) { // 检查是否为 JAXBElement |
| | | JAXBElement jaxbElement = (JAXBElement)obj; |
| | | Tbl table = (Tbl) XmlUtils.deepCopy(jaxbElement.getValue()); |
| | | targetIndex++; |
| | | // 插入到目标段落之后 |
| | | targetContent.add(targetIndex, table); |
| | | forms.add(table); |
| | | // 插入分页符 |
| | | P paragraphWithPageBreak = Context.getWmlObjectFactory().createP(); |
| | | R run = Context.getWmlObjectFactory().createR(); |
| | | Br br = Context.getWmlObjectFactory().createBr(); |
| | | br.setType(STBrType.PAGE); // 设置分页符类型 |
| | | run.getContent().add(br); |
| | | paragraphWithPageBreak.getContent().add(run); |
| | | targetIndex++; |
| | | targetContent.add(targetIndex, paragraphWithPageBreak); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 保存修改后的文档 |
| | | targetDoc.save(new File(path)); |
| | | com.spire.doc.Document document = new com.spire.doc.Document(); |
| | | document.loadFromFile(path); |
| | | // 更新目录 |
| | | document.updateTableOfContents(); |
| | | // 保存文档 |
| | | document.saveToFile(path, FileFormat.Docx); |
| | | document.close(); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | //电路报告用于总报告的方法(天线) |
| | | private void getWord1(String term, InsOrderState insOrderState, List<Map<String, Object>> tables2) { |
| | |
| | | if (inspectionItemSubclass.contains("互调")) { |
| | | aa += (angles + 1) * portRow * often; |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | if (inspectionItemSubclass.contains("电压驻波比")) { |
| | | aa += (angles + 1) * portRow; |
| | | } |
| | |
| | | int qq = 0; |
| | | int ss = 0; |
| | | //表格的行数 |
| | | for (int i = 0; i <= aa; i++) { |
| | | for (int i = 0; i <= aa+1; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | if (i == 0) { |
| | | if (i==0){ |
| | | if (j==0){ |
| | | textRenderData.setText("序号"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else if (j == 1) { |
| | | textRenderData.setText("检验项目"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else if (j == 2) { |
| | | textRenderData.setText("单位"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else if (j == 3) { |
| | | textRenderData.setText("标准与要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else if (j == bb-1) { |
| | | textRenderData.setText("检验结论"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else { |
| | | textRenderData.setText("检验结果∑5476" + i); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | else if (i == 1) { |
| | | //第一行 |
| | | textRenderData.setText("频段:" + s + "∑0" + lable); |
| | | renderData.add(textRenderData); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } |
| | | else { |
| | | int u = i; |
| | | i=i-1; |
| | | if (insOrderState.getVersion() == 1) { |
| | | //非电调版本(简单版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= 2 * portRow) { |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == bb - 1) { |
| | | } |
| | | else if (j == bb - 1) { |
| | | //最后一列 |
| | | if (i % 2 == 0) { |
| | | //结论 |
| | |
| | | textRenderData.setText("不判定"); |
| | | } |
| | | } else { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } |
| | | else { |
| | | //其余列 |
| | | if (i % 2 == 0) { |
| | | //最差值 |
| | |
| | | } else if (j == 4) { |
| | | //第五列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("角度"); |
| | | textRenderData.setText("频段"); |
| | | } else { |
| | | textRenderData.setText(result2s.get(0).getAngle().split(",")[(i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 2) % (angles + 1)]); |
| | | } |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | if (products.get(0).getInsResult() == 1) { |
| | | textRenderData.setText("合格∑8" + index + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) + (angles - 1)) / (angles + 1) - 1)); |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if (i % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - cc) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (dd == 0 ? cc : dd)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | //第五列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | //角度 |
| | | textRenderData.setText("角度"); |
| | | textRenderData.setText("频段"); |
| | | } else { |
| | | //值 |
| | | textRenderData.setText(result2s.get(0).getAngle().split(",")[(i + (angles - 1)) % (angles + 1)]); |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp)) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | int k = (angles + 1) * portRow2; |
| | | int rr = qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq; |
| | | if (i > rr && i <= rr + k) { |
| | | ss = (rr + k) ; |
| | | ss = (rr + k); |
| | | if (itemSet.add("最大相位偏差")) { |
| | | index.getAndIncrement(); |
| | | } |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - rr) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | int length = result2s.get(0).getPort().split(",").length; |
| | | int portRow2 = (length % 8 == 0 ? length / 8 : length / 8 + 1); |
| | | int k = (angles + 1) * portRow2; |
| | | int rr =ss==0?( qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq) : ss; |
| | | int rr = ss == 0 ? (qq == 0 ? (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp) : qq) : ss; |
| | | if (i > ss) { |
| | | if (itemSet.add("相位绝对值")) { |
| | | index.getAndIncrement(); |
| | |
| | | } else if (j == bb - 1) { |
| | | //最后一列 |
| | | if ((i - ss) % (angles + 1) == 1) { |
| | | textRenderData.setText("/"); |
| | | textRenderData.setText("判定"); |
| | | } else { |
| | | //结论 |
| | | if (products.get(0).getInsResult() == 1) { |
| | |
| | | } |
| | | } |
| | | } |
| | | i=u; |
| | | } |
| | | } |
| | | rowRenderData.setCells(cells); |
| | |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | Set<String> itemSet = new HashSet<>(); |
| | | //表格的行数 |
| | | for (int i = 0; i < result2VOS.size(); i++) { |
| | | for (int i = 0; i < result2VOS.size()+1; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | } |
| | | else if (j == 1) { |
| | | //第二列(检验项目) |
| | | textRenderData.setText(result2VOS.get(i).getInspectionItemSubclass() + "∑2" + index); |
| | | renderData.add(textRenderData); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 2) { |
| | | } |
| | | else if (j == 2) { |
| | | //第三列(单位) |
| | | textRenderData.setText(result2VOS.get(i).getUnit() + "∑3" + index); |
| | | renderData.add(textRenderData); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 查找文本首次出现行 |
| | | private int findFirstTargetIndex(WordprocessingMLPackage targetDoc,String textStr){ |
| | | int targetIndex = -1; |
| | | if(StringUtils.isEmpty(textStr)){ |
| | | return targetIndex; |
| | | } |
| | | try { |
| | | List<Object> targetContent = targetDoc.getMainDocumentPart().getContent(); |
| | | // 查找目标段落 |
| | | for (int i = 0; i < targetContent.size(); i++) { |
| | | Object obj = targetContent.get(i); |
| | | if (obj instanceof P) { |
| | | P paragraph = (P) obj; |
| | | for (Object runObj : paragraph.getContent()) { |
| | | if (runObj instanceof R) { |
| | | R run = (R) runObj; |
| | | for (Object textObj : run.getContent()) { |
| | | if (textObj instanceof JAXBElement) { |
| | | JAXBElement jaxbElement = (JAXBElement) textObj; |
| | | if(jaxbElement.getValue() instanceof Text){ |
| | | Text text = (Text) jaxbElement.getValue(); |
| | | if (text.getValue().contains(textStr)) { |
| | | targetIndex = i; |
| | | return targetIndex; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("findFirstTargetIndex<<<<<<<<<<:{}",e.getMessage()); |
| | | }finally { |
| | | return targetIndex; |
| | | } |
| | | } |
| | | } |