| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aspose.words.License; |
| | | import com.aspose.words.SaveFormat; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | |
| | | */ |
| | | @Service |
| | | public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService { |
| | | |
| | | private static final int DETECTION_REPORT = 0; |
| | | private static final int INSPECTION_REPORT = 1; |
| | | |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory) { |
| | | public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory, Integer reportType) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | List<String> collect = new ArrayList<>(); |
| | | if (Objects.equals(DETECTION_REPORT, reportType)) { |
| | | map.put("errorMsg", collect); |
| | | map.put("unInsOrderCount", 0L); |
| | | return map; |
| | | } |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId)); |
| | | List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList()); |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode,Boolean registerInsResults) { |
| | | InsOrder order = insOrderMapper.selectById(orderId); |
| | | public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode, Boolean registerInsResults, Integer reportType) { |
| | | if (!Objects.equals(DETECTION_REPORT, reportType) && !Objects.equals(INSPECTION_REPORT, reportType)) { |
| | | throw new ErrorException("请选择报告类型"); |
| | | } |
| | | InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery() |
| | | .eq(InsOrder::getId, orderId) |
| | | .last("FOR UPDATE")); |
| | | InsReport existingReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery() |
| | | .eq(InsReport::getInsOrderId, orderId)); |
| | | if (existingReport != null && existingReport.getReportType() != null |
| | | && !Objects.equals(existingReport.getReportType(), reportType)) { |
| | | throw new ErrorException("同一检验订单只能使用一种报告类型"); |
| | | } |
| | | boolean isInspectionReport = Objects.equals(INSPECTION_REPORT, reportType); |
| | | registerInsResults = isInspectionReport && Boolean.TRUE.equals(registerInsResults); |
| | | // 1. 判断是否有重复编号, 有重复编号做提醒 |
| | | Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery() |
| | | .ne(InsOrder::getState, -1) |
| | |
| | | .in(InsProduct::getInsSampleId, InsSampleIds) |
| | | .eq(InsProduct::getSonLaboratory, laboratory) |
| | | .eq(InsProduct::getState, 1) |
| | | .and(wrapper -> wrapper |
| | | .isNull(InsProduct::getInsResult) |
| | | .or() |
| | | .eq(InsProduct::getInsResult, 2) |
| | | ) |
| | | .and(wrapper -> { |
| | | if (Objects.equals(reportType, DETECTION_REPORT)) { |
| | | wrapper.isNull(InsProduct::getLastValue).or().eq(InsProduct::getLastValue, ""); |
| | | } else { |
| | | wrapper.isNull(InsProduct::getInsResult).or().eq(InsProduct::getInsResult, 2); |
| | | } |
| | | }) |
| | | .ne(InsProduct::getIsBinding, 1)); |
| | | insProducts.addAll(insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory)); |
| | | if (Objects.equals(reportType, INSPECTION_REPORT)) { |
| | | List<InsProduct> insProducts1 = insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory); |
| | | insProducts.addAll(insProducts1); |
| | | } |
| | | if (insProducts.size() > 0) { |
| | | String str = ""; |
| | | int count = 0; |
| | |
| | | }); |
| | | |
| | | // 8.提交生成报告 |
| | | this.generateReport(orderId); |
| | | this.generateReport(orderId, reportType); |
| | | |
| | | // 9.添加临时pdf生成地址 |
| | | InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery() |
| | |
| | | |
| | | // 11.成品抽样添加合格状态 |
| | | // 判断是否有抽样信息 |
| | | if (order.getQuarterItemId() != null) { |
| | | if (isInspectionReport && order.getQuarterItemId() != null) { |
| | | // 判断是否有不合格 |
| | | this.addProductSpotCheck(insSamples, order); |
| | | } |
| | |
| | | }); |
| | | |
| | | // 14.ifs移库(原材料需要进行移库操作) --> 最后执行,因为失败无法回滚 |
| | | if (ifsInventoryQuantity != null) { |
| | | if (ifsInventoryQuantity != null && isInspectionReport) { |
| | | // 登记检验结果 |
| | | // 判断是否有不合格, 有不合格不能移库 |
| | | // todo: ifs移库 |
| | |
| | | }); |
| | | |
| | | |
| | | } else { |
| | | } else if (isInspectionReport) { |
| | | // 修改成品状态 |
| | | // 判断是否有不合格 |
| | | Long unqualifiedCount = insReportService.getUnqualifiedCount(order); |
| | |
| | | private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String sendUserAccount) { |
| | | for (InsProduct insProduct : productList) { |
| | | // 判断是否是数值类型 |
| | | if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) { |
| | | if ("1".equals(insProduct.getInspectionValueType()) && Objects.equals(insProduct.getInsResult(), 1)) { |
| | | List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); |
| | | |
| | | if (CollectionUtils.isEmpty(insProductAnalysisDtoList)) { |
| | |
| | | * 生成报告 |
| | | * @param orderId |
| | | */ |
| | | private void generateReport(Integer orderId) { |
| | | private void generateReport(Integer orderId, Integer reportType) { |
| | | /*样品下的项目只要有一个项目不合格则检验结果为0,否则为1*/ |
| | | //这里的insSamples是订单下的所有样品包括("/") |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); |
| | | if (Objects.equals(reportType, INSPECTION_REPORT)) { |
| | | for (InsSample insSample : insSamples) { |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, insSample.getId()) |
| | | .eq(InsProduct::getState, 1) |
| | | .ne(InsProduct::getIsBinding, 1)); |
| | | List<Integer> results = insProducts.stream().map(InsProduct::getInsResult).filter(str -> str != null).collect(Collectors.toList()); |
| | | List<Integer> results = insProducts.stream().map(InsProduct::getInsResult).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | if (results.contains(0)) { |
| | | insSample.setInsResult(0); |
| | | } else { |
| | | insSample.setInsResult(1); |
| | | } |
| | | insSampleMapper.updateById(insSample); |
| | | } |
| | | } |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | // 抽检变成委托检验 |
| | |
| | | // 判断是大报告还是小报告 进厂小报告, 其他都是大报告 |
| | | if (insOrder.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) { |
| | | // 生成小报告 |
| | | addSmallReport(orderId, insOrder, insSamples); |
| | | addSmallReport(orderId, insOrder, insSamples, reportType); |
| | | } else { |
| | | //生成大报告 |
| | | addBitReport(orderId, insOrder); |
| | | addBitReport(orderId, insOrder, reportType); |
| | | } |
| | | |
| | | } |
| | |
| | | * @param max 标识最大个数 |
| | | * @return |
| | | */ |
| | | private TableStyle setTableStyle(int max){ |
| | | private TableStyle setTableStyle(int max, boolean showResult){ |
| | | //设置样式 |
| | | TableStyle tableStyle = new TableStyle(); |
| | | if(max<=5){ |
| | | if (!showResult) { |
| | | switch (max) { |
| | | case 1: tableStyle.setColWidths(new int[]{650, 3000, 850, 2400, 3100}); break; |
| | | case 2: tableStyle.setColWidths(new int[]{650, 2800, 850, 2200, 1750, 1750}); break; |
| | | case 3: tableStyle.setColWidths(new int[]{650, 2600, 850, 1800, 1400, 1400, 1400}); break; |
| | | case 4: tableStyle.setColWidths(new int[]{650, 2400, 850, 1600, 1125, 1125, 1125, 1125}); break; |
| | | case 5: tableStyle.setColWidths(new int[]{650, 2200, 850, 1500, 960, 960, 960, 960, 960}); break; |
| | | default: break; |
| | | } |
| | | } else if(max<=5){ |
| | | for (int i = 1; i <= max; i++) { |
| | | // 根据检验结果个数修改长度 |
| | | switch (i) { |
| | |
| | | * @param insOrder |
| | | * @param insSamples |
| | | */ |
| | | private void addSmallReport(Integer orderId, InsOrder insOrder, List<InsSample> insSamples) { |
| | | private void addSmallReport(Integer orderId, InsOrder insOrder, List<InsSample> insSamples, Integer reportType) { |
| | | InsReport insReport = new InsReport(); |
| | | AtomicReference<String> resultCh = new AtomicReference<>(""); |
| | | boolean showResult = Objects.equals(reportType, INSPECTION_REPORT); |
| | | insReport.setCode(insOrder.getEntrustCode()); |
| | | insReport.setInsOrderId(orderId); |
| | | insReport.setReportType(reportType); |
| | | InsSample insSample = insSamples.get(0); |
| | | // 填充基础数据 |
| | | EnterFactoryReport enterFactoryReport = new EnterFactoryReport(); |
| | |
| | | String templateName; |
| | | if(StringUtils.equals(OrderType.WG.getValue(),ifsInventoryQuantity.getOrderType())){ |
| | | //过滤不判定的检测项 |
| | | List<SampleProductExportDto> filterItems = sampleProductDto2s.stream().filter(f -> f.getInsResult() != 3).collect(Collectors.toList()); |
| | | List<SampleProductExportDto> filterItems = sampleProductDto2s.stream() |
| | | .filter(f -> !showResult || f.getInsResult() != 3) |
| | | .collect(Collectors.toList()); |
| | | int maxCableTag = 5;//单个表格,电缆颜色标识最大个数 |
| | | templateName = "/static/small-wg-report-template.docx"; |
| | | templateName = showResult ? "/static/small-wg-report-template.docx" : "/static/small-wg-detection-template.docx"; |
| | | //查询检验单消息 |
| | | InsSampleUserVO insSampleUser = insSampleUserMapper.selectUserNameByOrderId(orderId); |
| | | if(Objects.nonNull(insSampleUser)){ |
| | |
| | | sortSampleProduct(tempMap,totalItem); |
| | | int tagNum = Math.min(max,maxCableTag); |
| | | List<String> tagList = cableTags.isEmpty()?new ArrayList<>():cableTags.subList(0,tagNum); |
| | | handlerSampleItems(OrderType.WG.getValue(),totalItem,finalIndex,sampleList,tagNum,text,rows,rowRenderData,resultCh,tagList,true); |
| | | handlerSampleItems(OrderType.WG.getValue(), totalItem, finalIndex, sampleList, tagNum, text, rows, rowRenderData, resultCh, tagList, true, showResult); |
| | | |
| | | if(CollectionUtil.isNotEmpty(tempMap2)){ |
| | | sortSampleProduct(tempMap2,cableTagEnclosureItem); |
| | |
| | | List<TextRenderData> newText = new ArrayList<TextRenderData>(); |
| | | List<RowRenderData> newRows = new ArrayList<>(); |
| | | RowRenderData newRowRenderData = null; |
| | | handlerSampleItems(OrderType.WG.getValue(),cableTagEnclosureItem,finalIndex2, new ArrayList<>(),newCableTags.size(),newText,newRows,newRowRenderData,resultCh,newCableTags,true); |
| | | handlerSampleItems(OrderType.WG.getValue(), cableTagEnclosureItem, finalIndex2, new ArrayList<>(), newCableTags.size(), newText, newRows, newRowRenderData, resultCh, newCableTags, true, showResult); |
| | | tableRenderData2.setRows(newRows); |
| | | tableRenderData2.setTableStyle(setTableStyle(newCableTags.size())); |
| | | tableRenderData2.setTableStyle(setTableStyle(newCableTags.size(), showResult)); |
| | | HashMap<String, Object> tableMap = new HashMap<>(); |
| | | tableMap.put("enclosureTable",tableRenderData2); |
| | | tableMap.put("resultCh", resultCh); |
| | |
| | | } |
| | | |
| | | tableRenderData.setRows(rows); |
| | | tableRenderData.setTableStyle(setTableStyle(tagNum)); |
| | | if (!resultCh.get().isEmpty()) { |
| | | tableRenderData.setTableStyle(setTableStyle(tagNum, showResult)); |
| | | if (showResult && !resultCh.get().isEmpty()) { |
| | | resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。(盖章有效)"); |
| | | } else { |
| | | } else if (showResult) { |
| | | resultCh.set("本产品符合相关标准要求,经检验合格准予出厂(盖章有效)"); |
| | | } |
| | | |
| | | }else{ |
| | | templateName = "/static/small-report-template.docx"; |
| | | templateName = showResult ? "/static/small-report-template.docx" : "/static/small-detection-template.docx"; |
| | | // 转成Mpa进行排序 |
| | | Map<String, List<SampleProductExportDto>> sortedMap = sampleProductDto2s.stream() |
| | | .filter(sampleProductDto2 -> StringUtils.isNotBlank(sampleProductDto2.getInspectionItem())) |
| | |
| | | |
| | | |
| | | AtomicInteger finalIndex = new AtomicInteger(1); |
| | | handlerSampleItems(OrderType.RAW.getValue(), item,finalIndex,sampleList,max,text,rows,rowRenderData,resultCh,null,true); |
| | | handlerSampleItems(OrderType.RAW.getValue(), item, finalIndex, sampleList, max, text, rows, rowRenderData, resultCh, null, true, showResult); |
| | | tableRenderData.setRows(rows); |
| | | tableRenderData.setTableStyle(setTableStyle(max)); |
| | | tableRenderData.setTableStyle(setTableStyle(max, showResult)); |
| | | |
| | | if (!resultCh.get().equals("")) { |
| | | if (showResult && !resultCh.get().equals("")) { |
| | | resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。"); |
| | | } else { |
| | | } else if (showResult) { |
| | | resultCh.set("经检验此批" + enterFactoryReport.getSample() + "各项目均符合检验规范要求。"); |
| | | } |
| | | } |
| | |
| | | try { |
| | | // 修改换行和合并问题 |
| | | updaeMerge(template.getXWPFDocument(), true); |
| | | String name = insReport.getCode().replace("/", "") + "-J.docx"; |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); |
| | | String name = insReport.getCode().replace("/", "") + (showResult ? "-J.docx" : "-C.docx"); |
| | | Files.createDirectories(Paths.get(wordUrl)); |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl, name))); |
| | | insReport.setUrl("/word/" + name); |
| | | insReport.setIsPass(0); |
| | | insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人 |
| | |
| | | * @param rowRenderData |
| | | * @param resultCh |
| | | */ |
| | | private static void handlerSampleItems(String orderType,Map<String, List<SampleProductExportDto>> item,AtomicInteger finalIndex,List<SampleProductExportDto> sampleList,Integer max,List<TextRenderData> text,List<RowRenderData> rows,RowRenderData rowRenderData,AtomicReference<String> resultCh,List<String> cableTagList,Boolean hasAddHead ){ |
| | | private static void handlerSampleItems(String orderType, Map<String, List<SampleProductExportDto>> item, AtomicInteger finalIndex, List<SampleProductExportDto> sampleList, Integer max, List<TextRenderData> text, List<RowRenderData> rows, RowRenderData rowRenderData, AtomicReference<String> resultCh, List<String> cableTagList, Boolean hasAddHead, boolean showResult) { |
| | | item.forEach((s, sampleProductDtoInside) -> { |
| | | // 添加检验项 |
| | | SampleProductExportDto dto2 = new SampleProductExportDto(); |
| | |
| | | |
| | | // 添加小报告表头 |
| | | if(hasAddHead){ |
| | | text = addSmallHead(text, max, rows,cableTagList); |
| | | text = addSmallHead(text, max, rows, cableTagList, showResult); |
| | | } |
| | | |
| | | // 中间检测值添加 |
| | |
| | | if (CollectionUtils.isNotEmpty(sample.getLastValueList()) |
| | | && sample.getLastValueList().size() == max) { |
| | | // 判断是否是外观, 外观全部合格的话需要合并 |
| | | if (sample.getInspectionItem().contains("外观")) { |
| | | if (showResult && sample.getInspectionItem().contains("外观")) { |
| | | // 判定结果 |
| | | boolean falg = false; |
| | | if (CollectionUtils.isNotEmpty(sample.getLastValueList())) { |
| | | // 判断是否有一个错误 |
| | | if (sample.getInsResultList().stream().anyMatch(s -> s.equals(2))) { |
| | | if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 2))) { |
| | | falg = true; |
| | | } else { |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0)); |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0)); |
| | | if (!error) { |
| | | falg = true; |
| | | } |
| | | } |
| | | } else { |
| | | if (!sample.getInsResult().equals(2)) { |
| | | if (!Objects.equals(sample.getInsResult(), 2)) { |
| | | falg = true; |
| | | } |
| | | } |
| | |
| | | |
| | | // 判定结果 |
| | | String result = ""; |
| | | if (sample.getInsResult() != null) { |
| | | if (showResult && sample.getInsResult() != null) { |
| | | switch (sample.getInsResult()) { |
| | | case 1: |
| | | result = "√"; |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (CollectionUtils.isNotEmpty(sample.getLastValueList())) { |
| | | if (showResult && CollectionUtils.isNotEmpty(sample.getLastValueList())) { |
| | | // 判断是否有一个错误 |
| | | if (sample.getInsResultList().stream().anyMatch(s -> s.equals(3))) { |
| | | if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 3))) { |
| | | result = "-"; |
| | | } else { |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0)); |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0)); |
| | | if (error) { |
| | | List<String> collect = new ArrayList<>(); |
| | | int index = 1; |
| | | for (Integer count : sample.getInsResultList()) { |
| | | String type; |
| | | if (count.equals(0)) { |
| | | if (Objects.equals(count, 0)) { |
| | | // 添加不合格描述 |
| | | String item1 = (max == 1 ? "" : "第" + index + "次") |
| | | + sample.getInspectionItem() |
| | |
| | | } |
| | | } |
| | | |
| | | if (showResult) { |
| | | TextRenderData middleRenderData7 = new TextRenderData(); |
| | | middleRenderData7.setText(result); |
| | | Style middleStyle7 = new Style(); |
| | |
| | | middleStyle7.setColor("000000"); |
| | | middleRenderData7.setStyle(middleStyle7); |
| | | text.add(middleRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text2 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create(); |
| | |
| | | * @param rows |
| | | * @return |
| | | */ |
| | | private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows,List<String> cableTagList) { |
| | | private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows, List<String> cableTagList, boolean showResult) { |
| | | RowRenderData rowRenderData; |
| | | // // 头 |
| | | TextRenderData headRenderData1 = new TextRenderData(); |
| | |
| | | |
| | | for (int i = 0; i < max; i++) { |
| | | TextRenderData headRenderData6 = new TextRenderData(); |
| | | headRenderData6.setText("检验结果∑6"); |
| | | headRenderData6.setText(showResult ? "检验结果∑6" : "检测数据∑6"); |
| | | Style headStyle6 = new Style(); |
| | | headStyle6.setFontFamily("宋体"); |
| | | headStyle6.setColor("000000"); |
| | | headRenderData6.setStyle(headStyle6); |
| | | text.add(headRenderData6); |
| | | } |
| | | if (showResult) { |
| | | TextRenderData headRenderData7 = new TextRenderData(); |
| | | headRenderData7.setText("单项判断"); |
| | | Style headStyle7 = new Style(); |
| | |
| | | headStyle7.setColor("000000"); |
| | | headRenderData7.setStyle(headStyle7); |
| | | text.add(headRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text3 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text3).center().rowAtleastHeight(1).create(); |
| | |
| | | tagRenderData6.setStyle(tagStyle6); |
| | | text.add(tagRenderData6); |
| | | } |
| | | if (showResult) { |
| | | TextRenderData tagRenderData7 = new TextRenderData(); |
| | | tagRenderData7.setText(""); |
| | | Style tagStyle7 = new Style(); |
| | |
| | | tagStyle7.setColor("000000"); |
| | | tagRenderData7.setStyle(tagStyle7); |
| | | text.add(tagRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text4 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create(); |
| | |
| | | tagRenderData6.setStyle(tagStyle6); |
| | | text.add(tagRenderData6); |
| | | } |
| | | if (showResult) { |
| | | TextRenderData tagRenderData7 = new TextRenderData(); |
| | | tagRenderData7.setText("/"); |
| | | Style tagStyle7 = new Style(); |
| | |
| | | tagStyle7.setColor("000000"); |
| | | tagRenderData7.setStyle(tagStyle7); |
| | | text.add(tagRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text4 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create(); |
| | |
| | | * @param insOrder |
| | | * @param |
| | | */ |
| | | private void addBitReport(Integer orderId, InsOrder insOrder) { |
| | | private void addBitReport(Integer orderId, InsOrder insOrder, Integer reportType) { |
| | | //samples是不包括带有"/"的样品 |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(insOrder.getEntrustCode()); |
| | | insReport.setInsOrderId(orderId); |
| | | insReport.setReportType(reportType); |
| | | boolean showResult = Objects.equals(reportType, INSPECTION_REPORT); |
| | | List<Map<String, Object>> tables = new ArrayList<>(); |
| | | Set<String> standardMethod = new HashSet<>(); |
| | | Set<String> deviceSet = new HashSet<>(); |
| | |
| | | List<String> resultChList = new ArrayList<>(); |
| | | List<String> resultEnList = new ArrayList<>(); |
| | | // 判断是否是只有一个样品 |
| | | boolean isOneSample = samples.size() == 1 ? true : false; |
| | | boolean isOneSample = samples.size() == 1; |
| | | /*基础报告(根据绘制的原始记录模版形成)*/ |
| | | samples.forEach(a -> { |
| | | models.add(a.getModel()); |
| | |
| | | } |
| | | |
| | | // 表头添加 |
| | | addHead(a, text, rowRenderData, rows, max, cableTags); |
| | | addHead(a, text, rowRenderData, rows, max, cableTags, showResult); |
| | | text = new ArrayList<>(); |
| | | |
| | | // 添加检测值 |
| | | productSize.set(addTestValue(a, text, rowRenderData, rows, max, resultChList, resultEnList, insSamples, cableTags, isOneSample)); |
| | | productSize.set(addTestValue(a, text, rowRenderData, rows, max, resultChList, resultEnList, insSamples, cableTags, isOneSample, showResult)); |
| | | text = new ArrayList<>(); |
| | | |
| | | // 结尾添加 |
| | | addEnding(text, rowRenderData, rows, max); |
| | | addEnding(text, rowRenderData, rows, max, showResult); |
| | | text = new ArrayList<>(); |
| | | |
| | | List<TableRenderData> tables1 = new ArrayList<>(); |
| | |
| | | // for (int i = 1; i <= max; i++) { |
| | | // } |
| | | // 根据检验结果个数修改长度 |
| | | tableStyle.setColWidths(calcTableColWidths(max)); |
| | | tableStyle.setColWidths(calcTableColWidths(max, showResult)); |
| | | // switch (max) { |
| | | // case 1: |
| | | // tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | |
| | | // for (int i = 1; i <= max; i++) { |
| | | // } |
| | | // 根据检验结果个数修改长度 |
| | | tableStyle.setColWidths(calcTableColWidths(max)); |
| | | tableStyle.setColWidths(calcTableColWidths(max, showResult)); |
| | | // switch (max) { |
| | | // case 1: |
| | | // tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | |
| | | Custom custom = customMapper.selectById(insOrder.getCompanyId()); |
| | | |
| | | // 查询判断是否有不判定项目,和全都是判定项 |
| | | int judgeType = insProductMapper.selectNoJudge(insOrder.getId()); |
| | | int judgeType = showResult ? insProductMapper.selectNoJudge(insOrder.getId()) : 0; |
| | | String resultCh = ""; |
| | | String resultEn = ""; |
| | | for (String reference : resultChList) { |
| | |
| | | List<Map<String, String>> finalDeviceList = deviceList; |
| | | String finalModelStr = modelStr; |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | InputStream inputStream = this.getClass().getResourceAsStream(showResult ? "/static/report-template.docx" : "/static/detection-report-template.docx"); |
| | | Configure configure = Configure.builder() |
| | | .bind("deviceList", new HackLoopTableRenderPolicy()) |
| | | .useSpringEL(true) |
| | |
| | | try { |
| | | // 修改换行和合并问题 |
| | | updaeMerge(template.getXWPFDocument(), false); |
| | | String name = insReport.getCode().replace("/", "") + ".docx"; |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); |
| | | String name = insReport.getCode().replace("/", "") + (showResult ? ".docx" : "-C.docx"); |
| | | Files.createDirectories(Paths.get(wordUrl)); |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl, name))); |
| | | insReport.setUrl("/word/" + name); |
| | | insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人 |
| | | insReport.setWriteTime(LocalDateTime.now());//提交时间 |
| | |
| | | * @param max 最大检验个数 |
| | | * @return |
| | | */ |
| | | private static int[] calcTableColWidths(int max){ |
| | | private static int[] calcTableColWidths(int max, boolean showResult){ |
| | | if (!showResult) { |
| | | switch (max) { |
| | | case 1: return new int[]{650, 2200, 2200, 850, 2300, 1800}; |
| | | case 2: return new int[]{650, 1600, 1600, 850, 1900, 1700, 1700}; |
| | | case 3: return new int[]{650, 1400, 1400, 850, 1600, 1375, 1375, 1375}; |
| | | case 4: return new int[]{650, 1250, 1250, 850, 1450, 1140, 1140, 1140, 1140}; |
| | | case 5: return new int[]{650, 1150, 1150, 850, 1300, 980, 980, 980, 980, 980}; |
| | | default: return new int[0]; |
| | | } |
| | | } |
| | | int[] colWidths = null; |
| | | switch (max) { |
| | | case 1: |
| | |
| | | * @param max |
| | | * @param cableTags 线芯颜色 |
| | | */ |
| | | private static void addHead(SampleProductDto sample, List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, List<String> cableTags) { |
| | | private static void addHead(SampleProductDto sample, List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, List<String> cableTags, boolean showResult) { |
| | | // 第一行 |
| | | TextRenderData firstRenderData1 = new TextRenderData(); |
| | | firstRenderData1.setText("样品编号@Sample No.∑1"); |
| | |
| | | } |
| | | |
| | | } |
| | | // 检测报告不展示“结论”列,首行也要同步减少一个单元格, |
| | | // 否则首行为 max + 6 列、其余行为 max + 5 列,poi-tl 无法渲染表格。 |
| | | if (!showResult && !text.isEmpty()) { |
| | | text.remove(text.size() - 1); |
| | | } |
| | | TextRenderData[] text2 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create(); |
| | | rows.add(rowRenderData); |
| | |
| | | |
| | | for (int i = 0; i < max; i++) { |
| | | TextRenderData headRenderData6 = new TextRenderData(); |
| | | headRenderData6.setText("检验结果@Test result∑6"); |
| | | headRenderData6.setText(showResult ? "检验结果@Test result∑6" : "检测数据@Test data∑6"); |
| | | Style headStyle6 = new Style(); |
| | | headStyle6.setFontFamily("宋体"); |
| | | headStyle6.setColor("000000"); |
| | | headRenderData6.setStyle(headStyle6); |
| | | text.add(headRenderData6); |
| | | } |
| | | if (showResult) { |
| | | TextRenderData headRenderData7 = new TextRenderData(); |
| | | headRenderData7.setText("结论@Conclusion"); |
| | | Style headStyle7 = new Style(); |
| | |
| | | headStyle7.setColor("000000"); |
| | | headRenderData7.setStyle(headStyle7); |
| | | text.add(headRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text3 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text3).center().rowAtleastHeight(1).create(); |
| | |
| | | cableRenderData6.setStyle(cableStyle6); |
| | | text.add(cableRenderData6); |
| | | } |
| | | if (showResult) { |
| | | TextRenderData cableRenderData7 = new TextRenderData(); |
| | | cableRenderData7.setText("-"); |
| | | Style cableStyle7 = new Style(); |
| | |
| | | cableStyle7.setColor("000000"); |
| | | cableRenderData7.setStyle(cableStyle7); |
| | | text.add(cableRenderData7); |
| | | } |
| | | |
| | | TextRenderData[] text4 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create(); |
| | |
| | | List<String> resultChList, |
| | | List<String> resultEhList, |
| | | InsSample insSamples, List<String> cableTags, |
| | | boolean isOneSample) { |
| | | boolean isOneSample, boolean showResult) { |
| | | // 检验项总数 |
| | | AtomicInteger productSize = new AtomicInteger(1); |
| | | // 不合格信息 |
| | |
| | | // 检验项分类 检验项 检验子项 |
| | | Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapCn = new LinkedHashMap<>(); |
| | | Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapEn = new LinkedHashMap<>(); |
| | | |
| | | // 中间检测值添加 |
| | | for (int i = 0; i < sampleList.size(); i++) { |
| | | SampleProductExportDto sample = sampleList.get(i); |
| | |
| | | |
| | | // 判断是否有电缆标识map |
| | | if (CollectionUtils.isNotEmpty(sample.getCableTagValueMap())) { |
| | | sample.setLastValueList(new ArrayList<>(sample.getCableTagValueMap().values())); |
| | | TreeMap<String, String> cableTagValues = new TreeMap<>(Comparator.comparingInt(cableTags::indexOf)); |
| | | cableTagValues.putAll(sample.getCableTagValueMap()); |
| | | sample.setLastValueList(new ArrayList<>(cableTagValues.values())); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(sample.getCableTagResultMap())) { |
| | | sample.setInsResultList(new ArrayList<>(sample.getCableTagResultMap().values())); |
| | |
| | | } |
| | | } |
| | | // 判定结果 |
| | | if (showResult) { |
| | | String result = ""; |
| | | if (sample.getInsResult() != null) { |
| | | switch (sample.getInsResult()) { |
| | |
| | | } |
| | | if (CollectionUtils.isNotEmpty(sample.getLastValueList())) { |
| | | // 判断是否有一个错误 |
| | | if (sample.getInsResultList().stream().anyMatch(s -> s.equals(3))) { |
| | | if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 3))) { |
| | | result = "-"; |
| | | } else { |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0)); |
| | | boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0)); |
| | | if (error) { |
| | | List<String> collect = new ArrayList<>(); |
| | | int index = 0; |
| | | for (Integer count : sample.getInsResultList()) { |
| | | String type; |
| | | if (count.equals(0)) { |
| | | if (Objects.equals(count, 0)) { |
| | | String itemCh = ""; |
| | | String itemEn = ""; |
| | | // 添加不合格描述 |
| | |
| | | } |
| | | } |
| | | |
| | | if (showResult) { |
| | | TextRenderData headRenderData7 = new TextRenderData(); |
| | | headRenderData7.setText(result); |
| | | Style headStyle7 = new Style(); |
| | |
| | | headStyle7.setColor("000000"); |
| | | headRenderData7.setStyle(headStyle7); |
| | | text.add(headRenderData7); |
| | | } |
| | | } |
| | | |
| | | TextRenderData[] text2 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create(); |
| | |
| | | sampleProductDto2.setLastValue(sampleProductDto2.getLastValue().trim()); |
| | | } |
| | | |
| | | if (sampleProductDto2.getInsResult().equals(0)) { |
| | | if (Objects.equals(sampleProductDto2.getInsResult(), 0)) { |
| | | // 查询不合格复测 |
| | | Long count = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery() |
| | | .eq(InsUnqualifiedRetestProduct::getInsProductId, sampleProductDto2.getInsProductId()) |
| | |
| | | * @param rowRenderData |
| | | * @param rows |
| | | */ |
| | | private static void addEnding(List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max) { |
| | | private static void addEnding(List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, boolean showResult) { |
| | | for (int i = 0; i < 2; i++) { |
| | | TextRenderData endingRenderData = new TextRenderData(); |
| | | endingRenderData.setText("备注∑1999"); |
| | |
| | | text.add(endingRenderData); |
| | | } |
| | | |
| | | for (int i = 0; i < 5 + max - 1; i++) { |
| | | for (int i = 0; i < (showResult ? 5 : 4) + max - 1; i++) { |
| | | TextRenderData endingRenderData = new TextRenderData(); |
| | | endingRenderData.setText("“√”表示项目合格,“×”表示项目不合格,“-”表示不要判定,“/”表示没有标准要求。@“√” indicates test ltem is qualified,“×” indicates test ltem is unqualified,“-” indicates test ltem judgment is not required,“/” indicates test ltem is no test requirement.∑2000"); |
| | | endingRenderData.setText(showResult ? "“√”表示项目合格,“×”表示项目不合格,“-”表示不要判定,“/”表示没有标准要求。@“√” indicates test ltem is qualified,“×” indicates test ltem is unqualified,“-” indicates test ltem judgment is not required,“/” indicates test ltem is no test requirement.∑2000" : ""); |
| | | Style endingStyle = new Style(); |
| | | endingStyle.setFontFamily("宋体"); |
| | | endingStyle.setColor("000000"); |