| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | |
| | | 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; |
| | |
| | | import com.ruoyi.basic.pojo.IfsInventoryQuantity; |
| | | import com.ruoyi.basic.pojo.StandardTemplate; |
| | | import com.ruoyi.basic.service.StandardTemplateService; |
| | | import com.ruoyi.basic.vo.IfsInventoryQuantityVO; |
| | | import com.ruoyi.common.constant.DictDataConstants; |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.common.constant.MenuJumpPathConstants; |
| | | import com.ruoyi.common.core.domain.entity.Custom; |
| | | import com.ruoyi.common.core.domain.entity.InformationNotification; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.enums.OrderType; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.*; |
| | |
| | | import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo; |
| | | import com.ruoyi.inspect.vo.InsOrderPlanVO; |
| | | import com.ruoyi.inspect.vo.InsSampleUserVO; |
| | | import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper; |
| | | import com.ruoyi.performance.mapper.PerformanceShiftMapper; |
| | | import com.ruoyi.performance.mapper.ShiftTimeMapper; |
| | | import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours; |
| | | import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHoursTemporary; |
| | | import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursService; |
| | | import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursTemporaryService; |
| | | import com.ruoyi.system.mapper.CustomMapper; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import com.ruoyi.system.service.ISysDictTypeService; |
| | |
| | | import java.nio.file.Paths; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | |
| | | private InsOrderFileMapper insOrderFileMapper; |
| | | @Resource |
| | | private IfsInventoryQuantityMapper ifsInventoryQuantityMapper; |
| | | @Resource |
| | | private IfsPartPropsRecordMapper ifsPartPropsRecordMapper; |
| | | @Resource |
| | | private InsReportService insReportService; |
| | | @Resource |
| | |
| | | /***************************************************** 小报告 ***************************************************************************/ |
| | | |
| | | /** |
| | | * 设置表格样式 |
| | | * @param max 标识最大个数 |
| | | * @return |
| | | */ |
| | | private TableStyle setTableStyle(int max){ |
| | | //设置样式 |
| | | TableStyle tableStyle = new TableStyle(); |
| | | if(max<=5){ |
| | | for (int i = 1; i <= max; i++) { |
| | | // 根据检验结果个数修改长度 |
| | | switch (i) { |
| | | case 1: |
| | | tableStyle.setColWidths(new int[]{650, 2900, 850, 2300, 2100, 1200}); |
| | | break; |
| | | case 2: |
| | | tableStyle.setColWidths(new int[]{650, 2700, 850, 2200, 1200, 1200, 1200}); |
| | | break; |
| | | case 3: |
| | | tableStyle.setColWidths(new int[]{650, 2700, 850, 1600, 1000, 1000, 1000, 1200}); |
| | | break; |
| | | case 4: |
| | | tableStyle.setColWidths(new int[]{650, 2400, 850, 1500, 850, 850, 850, 850, 1200}); |
| | | break; |
| | | case 5: |
| | | tableStyle.setColWidths(new int[]{650, 2200, 850, 1350, 770, 770, 770, 770, 770, 1100}); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | tableStyle.setWidth("10000"); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE); |
| | | borderStyle.setSize(4); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setInsideHBorder(borderStyle); // 设置水平内边框 |
| | | tableStyle.setInsideVBorder(borderStyle); |
| | | return tableStyle; |
| | | } |
| | | |
| | | /** |
| | | * 处理有电缆颜色标识的检测项 |
| | | * @param cableTags 电缆颜色标识 |
| | | * @param collect 检测项列表 |
| | | * @param startIndex 起始下标 |
| | | * @param endIndex 结束下标 |
| | | * @return |
| | | */ |
| | | private List<SampleProductExportDto> transformSampleProduct(List<String> cableTags,Map<String, List<SampleProductExportDto>> collect,int startIndex,int endIndex){ |
| | | List<SampleProductExportDto> sampleProductExportDtos = new ArrayList<>(); |
| | | for (String s : collect.keySet()) { |
| | | List<String> lastValueList = new ArrayList<>(); |
| | | SampleProductExportDto dto = new SampleProductExportDto(); |
| | | BeanUtil.copyProperties(collect.get(s).get(0),dto); |
| | | Set<String> tellSet = new HashSet<>(); |
| | | for (int i = startIndex; i < endIndex; i++) { |
| | | String cableTag = cableTags.get(i); |
| | | for (SampleProductExportDto sDto : collect.get(s)) { |
| | | tellSet.add(sDto.getTell()); |
| | | if(sDto.getCableTag().equals(cableTag)){ |
| | | lastValueList.add(sDto.getLastValue()); |
| | | } |
| | | } |
| | | } |
| | | //切割电缆配置项 |
| | | dto.setTell(String.join("\n",tellSet)); |
| | | dto.setLastValueList(lastValueList); |
| | | sampleProductExportDtos.add(dto); |
| | | } |
| | | return sampleProductExportDtos; |
| | | } |
| | | |
| | | /** |
| | | * 检测项排序 |
| | | * @param sourceMap |
| | | * @param targetMap |
| | | */ |
| | | private void sortSampleProduct(Map<String, List<SampleProductExportDto>> sourceMap,Map<String, List<SampleProductExportDto>> targetMap){ |
| | | List<Map.Entry<String, List<SampleProductExportDto>>> entries = new ArrayList<>(sourceMap.entrySet()); |
| | | entries.sort(Comparator.comparingInt(o -> (o.getValue().get(0).getSort() == null ? 0 : o.getValue().get(0).getSort()))); |
| | | for (Map.Entry<String, List<SampleProductExportDto>> entry : entries) { |
| | | targetMap.put(entry.getKey(), entry.getValue()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 小报告生成 |
| | | * @param orderId |
| | | * @param insOrder |
| | |
| | | enterFactoryReport.setSample(insOrder.getSample()); |
| | | // 获取ifs数据 |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId()); |
| | | //查询零件属性 |
| | | IfsPartPropsRecord ifsPartPropsRecord = ifsPartPropsRecordMapper.selectOne(Wrappers.<IfsPartPropsRecord>lambdaQuery() |
| | | .eq(IfsPartPropsRecord::getIfsInventoryId, ifsInventoryQuantity.getId())); |
| | | if(Objects.nonNull(ifsPartPropsRecord)){ |
| | | enterFactoryReport.setOuterColor(ifsPartPropsRecord.getOuterColor()); |
| | | } |
| | | enterFactoryReport.setQtyArrived(ifsInventoryQuantity.getQtyArrived() == null ? "" : |
| | | ifsInventoryQuantity.getQtyArrived().stripTrailingZeros().toPlainString() + ifsInventoryQuantity.getBuyUnitMeas()); |
| | | enterFactoryReport.setQuantity(insOrder.getTestQuantity()); |
| | | enterFactoryReport.setPartDesc(insOrder.getPartDetail()); |
| | | enterFactoryReport.setSupplierName("**********"); |
| | | enterFactoryReport.setSupplierName(ifsInventoryQuantity.getSupplierName()); |
| | | enterFactoryReport.setLotBatchNo(ifsInventoryQuantity.getUpdateBatchNo()); |
| | | |
| | | // 检测依据 |
| | |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | List<TextRenderData> text = new ArrayList<>(); |
| | | RowRenderData rowRenderData = null; |
| | | List<Map<String,Object>> cableTagEnclosureTables = new ArrayList<>(); |
| | | |
| | | // 查询检验内容 |
| | | List<SampleProductExportDto> sampleProductDto2s = insOrderMapper.selectSampleBySampleId(insSamples.stream() |
| | |
| | | |
| | | List<SampleProductExportDto> sampleList = new ArrayList<>(); |
| | | Integer max = insSamples.stream().mapToInt(InsSample::getQuantity).sum(); |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | String templateName; |
| | | if(StringUtils.equals(OrderType.WG.getValue(),ifsInventoryQuantity.getOrderType())){ |
| | | //过滤不判定的检测项 |
| | | List<SampleProductExportDto> filterItems = sampleProductDto2s.stream().filter(f -> f.getInsResult() != 3).collect(Collectors.toList()); |
| | | int maxCableTag = 5;//单个表格,电缆颜色标识最大个数 |
| | | templateName = "/static/small-wg-report-template.docx"; |
| | | //查询检验单消息 |
| | | InsSampleUserVO insSampleUser = insSampleUserMapper.selectUserNameByOrderId(orderId); |
| | | if(Objects.nonNull(insSampleUser)){ |
| | | enterFactoryReport.setPartDesc(insSampleUser.getModel()); |
| | | enterFactoryReport.setInspector(insSampleUser.getInspector()); |
| | | enterFactoryReport.setInspectDate(insSampleUser.getInspectDate()); |
| | | } |
| | | |
| | | // 转成Mpa进行排序 |
| | | Map<String, List<SampleProductExportDto>> sortedMap = sampleProductDto2s.stream() |
| | | .filter(sampleProductDto2 -> StringUtils.isNotBlank(sampleProductDto2.getInspectionItem())) |
| | | .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem)); |
| | | List<Map.Entry<String, List<SampleProductExportDto>>> entries = new ArrayList<>(sortedMap.entrySet()); |
| | | entries.sort((o1, o2) -> (o1.getValue().get(0).getSort() == null ? 0 : o1.getValue().get(0).getSort()) |
| | | - (o2.getValue().get(0).getSort() == null ? 0 : o2.getValue().get(0).getSort())); |
| | | // 创建一个 LinkedHashMap 来保持插入顺序 |
| | | Map<String, List<SampleProductExportDto>> item = new LinkedHashMap<>(); |
| | | for (Map.Entry<String, List<SampleProductExportDto>> entry : entries) { |
| | | item.put(entry.getKey(), entry.getValue()); |
| | | Map<String, List<SampleProductExportDto>> item = new LinkedHashMap<>();//非电缆配置检测项 |
| | | Map<String, List<SampleProductExportDto>> cableTagItem = new LinkedHashMap<>();//电缆配置检测项 |
| | | Map<String, List<SampleProductExportDto>> cableTagEnclosureItem = new LinkedHashMap<>();//电缆配置检测项附件 |
| | | |
| | | AtomicInteger finalIndex = new AtomicInteger(1); |
| | | List<String> cableTags = insOrderMapper.selectSampleCableTag(insSample.getId()); |
| | | max = cableTags.size(); |
| | | //处理电缆配置检测项 |
| | | Map<String, List<SampleProductExportDto>> tempMap = new HashMap<>(); |
| | | Map<String, List<SampleProductExportDto>> tempMap2 = new HashMap<>(); |
| | | Map<String, List<SampleProductExportDto>> listMap2 = filterItems.stream() |
| | | .filter(f -> StringUtils.isNotBlank(f.getCableTag()) && StringUtils.isNotBlank(f.getInspectionItem())) |
| | | .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem)); |
| | | for (String key : listMap2.keySet()) { |
| | | List<SampleProductExportDto> sampleProductExportDtos; |
| | | List<SampleProductExportDto> sampleProductExportDtos2; |
| | | //处理电缆配置项 |
| | | Map<String, List<SampleProductExportDto>> collect = listMap2.get(key).stream().collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItemSubclass)); |
| | | if(cableTags.size()>maxCableTag){ |
| | | sampleProductExportDtos = transformSampleProduct(cableTags,collect,0,maxCableTag); |
| | | sampleProductExportDtos2 = transformSampleProduct(cableTags,collect,maxCableTag,cableTags.size()); |
| | | tempMap2.put(key,sampleProductExportDtos2); |
| | | }else{ |
| | | sampleProductExportDtos = transformSampleProduct(cableTags,collect,0,cableTags.size()); |
| | | } |
| | | tempMap.put(key,sampleProductExportDtos); |
| | | } |
| | | sortSampleProduct(tempMap,cableTagItem); |
| | | int tagNum = Math.min(max,maxCableTag); |
| | | List<String> tagList = cableTags.subList(0,tagNum); |
| | | handlerSampleItems(cableTagItem,finalIndex,sampleList,tagNum,text,rows,rowRenderData,resultCh,tagList,true); |
| | | |
| | | if(CollectionUtil.isNotEmpty(tempMap2)){ |
| | | sortSampleProduct(tempMap2,cableTagEnclosureItem); |
| | | //生成附件电缆表格 |
| | | TableRenderData tableRenderData2 = new TableRenderData(); |
| | | List<String> newCableTags = cableTags.subList(maxCableTag,cableTags.size()); |
| | | AtomicInteger finalIndex2 = new AtomicInteger(1); |
| | | List<TextRenderData> newText = new ArrayList<TextRenderData>(); |
| | | List<RowRenderData> newRows = new ArrayList<>(); |
| | | RowRenderData newRowRenderData = null; |
| | | handlerSampleItems(cableTagEnclosureItem,finalIndex2, new ArrayList<>(),newCableTags.size(),newText,newRows,newRowRenderData,resultCh,newCableTags,true); |
| | | tableRenderData2.setRows(newRows); |
| | | tableRenderData2.setTableStyle(setTableStyle(newCableTags.size())); |
| | | HashMap<String, Object> tableMap = new HashMap<>(); |
| | | tableMap.put("enclosureTable",tableRenderData2); |
| | | tableMap.put("resultCh", resultCh); |
| | | tableMap.put("writeUrl", null); |
| | | tableMap.put("examineUrl", null); |
| | | tableMap.put("ratifyUrl", null); |
| | | tableMap.put("writeDateUrl", null); |
| | | tableMap.put("examineDateUrl", null); |
| | | tableMap.put("ratifyDateUrl", null); |
| | | tableMap.put("seal1", null); |
| | | cableTagEnclosureTables.add(tableMap); |
| | | } |
| | | |
| | | //处理非电缆配置检测项 |
| | | Map<String, List<SampleProductExportDto>> listMap = filterItems.stream() |
| | | .filter(f -> StringUtils.isBlank(f.getCableTag()) && StringUtils.isNotBlank(f.getInspectionItem())) |
| | | .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem)); |
| | | sortSampleProduct(listMap,item); |
| | | text = new ArrayList<>(); |
| | | sampleList = new ArrayList<>(); |
| | | handlerSampleItems(item,finalIndex,sampleList,tagNum,text,rows,rowRenderData,resultCh,cableTags,false); |
| | | tableRenderData.setRows(rows); |
| | | tableRenderData.setTableStyle(setTableStyle(tagNum)); |
| | | if (!resultCh.get().equals("")) { |
| | | resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。(盖章有效)"); |
| | | } else { |
| | | resultCh.set("本产品符合相关标准要求,经检验合格准予出厂(盖章有效)"); |
| | | } |
| | | |
| | | }else{ |
| | | templateName = "/static/small-report-template.docx"; |
| | | // 转成Mpa进行排序 |
| | | Map<String, List<SampleProductExportDto>> sortedMap = sampleProductDto2s.stream() |
| | | .filter(sampleProductDto2 -> StringUtils.isNotBlank(sampleProductDto2.getInspectionItem())) |
| | | .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem)); |
| | | // List<Map.Entry<String, List<SampleProductExportDto>>> entries = new ArrayList<>(sortedMap.entrySet()); |
| | | // entries.sort(Comparator.comparingInt(o -> (o.getValue().get(0).getSort() == null ? 0 : o.getValue().get(0).getSort()))); |
| | | // // 创建一个 LinkedHashMap 来保持插入顺序 |
| | | Map<String, List<SampleProductExportDto>> item = new LinkedHashMap<>(); |
| | | // for (Map.Entry<String, List<SampleProductExportDto>> entry : entries) { |
| | | // item.put(entry.getKey(), entry.getValue()); |
| | | // } |
| | | sortSampleProduct(sortedMap,item); |
| | | |
| | | |
| | | AtomicInteger finalIndex = new AtomicInteger(1); |
| | | handlerSampleItems(item,finalIndex,sampleList,max,text,rows,rowRenderData,resultCh,null,true); |
| | | tableRenderData.setRows(rows); |
| | | tableRenderData.setTableStyle(setTableStyle(max)); |
| | | |
| | | if (!resultCh.get().equals("")) { |
| | | resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。"); |
| | | } else { |
| | | resultCh.set("经检验此批" + enterFactoryReport.getSample() + "各项目均符合检验规范要求。"); |
| | | } |
| | | } |
| | | |
| | | AtomicInteger finalIndex = new AtomicInteger(1); |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream(templateName); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("report", enterFactoryReport); |
| | | put("standardMethod", standardMethod2.toString().equals("null") ? "" : standardMethod2); |
| | | put("orderType", orderType); |
| | | put("table", tableRenderData); |
| | | put("enclosureTables", cableTagEnclosureTables.isEmpty()?null:cableTagEnclosureTables); |
| | | put("resultCh", resultCh); |
| | | put("writeUrl", null); |
| | | put("examineUrl", null); |
| | | put("ratifyUrl", null); |
| | | put("writeDateUrl", null); |
| | | put("examineDateUrl", null); |
| | | put("ratifyDateUrl", null); |
| | | put("seal1", null); |
| | | }}); |
| | | try { |
| | | // 修改换行和合并问题 |
| | | updaeMerge(template.getXWPFDocument(), true); |
| | | String name = insReport.getCode().replace("/", "") + "-J.docx"; |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); |
| | | insReport.setUrl("/word/" + name); |
| | | insReport.setIsPass(0); |
| | | insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人 |
| | | insReport.setWriteTime(LocalDateTime.now());//提交时间 |
| | | // 查询报告, 判断之前是否添加过, 添加过删除 |
| | | insReportMapper.delete(Wrappers.<InsReport>lambdaQuery() |
| | | .eq(InsReport::getInsOrderId, insOrder.getId())); |
| | | insReportMapper.insert(insReport); |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理常规检测项 |
| | | * @param item |
| | | * @param finalIndex |
| | | * @param sampleList |
| | | * @param max |
| | | * @param text |
| | | * @param rows |
| | | * @param rowRenderData |
| | | * @param resultCh |
| | | */ |
| | | private static void handlerSampleItems(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 ){ |
| | | item.forEach((s, sampleProductDtoInside) -> { |
| | | // 添加检验项 |
| | | SampleProductExportDto dto2 = new SampleProductExportDto(); |
| | |
| | | String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem(); |
| | | if (map.containsKey(productName)) { |
| | | // 如果名称已经存在,添加 lastValue 值到 lastValueList 列表 |
| | | map.get(productName) |
| | | .getLastValueList() |
| | | .add(productDto2.getLastValue()); |
| | | if(CollectionUtil.isEmpty(map.get(productName).getLastValueList())){ |
| | | map.get(productName) |
| | | .getLastValueList() |
| | | .add(productDto2.getLastValue()); |
| | | } |
| | | map.get(productName) |
| | | .getInsResultList() |
| | | .add(productDto2.getInsResult()); |
| | | } else { |
| | | // 如果名称不存在,直接放入 map |
| | | productDto2.setLastValueList(new ArrayList<>()); // 检验内容 |
| | | productDto2.getLastValueList().add(productDto2.getLastValue()); |
| | | if(CollectionUtil.isEmpty(productDto2.getLastValueList())){ |
| | | productDto2.setLastValueList(new ArrayList<>()); // 检验内容 |
| | | productDto2.getLastValueList().add(productDto2.getLastValue()); |
| | | } |
| | | productDto2.setInsResultList(new ArrayList<>()); // 结果 |
| | | productDto2.getInsResultList().add(productDto2.getInsResult()); |
| | | |
| | |
| | | String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem() + productDto2.getInspectionItemSubclass(); |
| | | if (map.containsKey(productName)) { |
| | | // 如果名称已经存在,添加 lastValue 值到 lastValueList 列表 |
| | | map.get(productName) |
| | | .getLastValueList() |
| | | .add(productDto2.getLastValue()); |
| | | if(CollectionUtil.isEmpty(map.get(productName).getLastValueList())){ |
| | | map.get(productName) |
| | | .getLastValueList() |
| | | .add(productDto2.getLastValue()); |
| | | } |
| | | map.get(productName) |
| | | .getInsResultList() |
| | | .add(productDto2.getInsResult()); |
| | | } else { |
| | | // 如果名称不存在,直接放入 map |
| | | productDto2.setLastValueList(new ArrayList<>()); // 检验内容 |
| | | productDto2.getLastValueList().add(productDto2.getLastValue()); |
| | | if(CollectionUtil.isEmpty(productDto2.getLastValueList())){ |
| | | productDto2.setLastValueList(new ArrayList<>()); // 检验内容 |
| | | productDto2.getLastValueList().add(productDto2.getLastValue()); |
| | | } |
| | | productDto2.setInsResultList(new ArrayList<>()); // 结果 |
| | | productDto2.getInsResultList().add(productDto2.getInsResult()); |
| | | |
| | |
| | | }); |
| | | |
| | | // 添加小报告表头 |
| | | text = addSmallHead(text, max, rows); |
| | | |
| | | if(hasAddHead){ |
| | | text = addSmallHead(text, max, rows,cableTagList); |
| | | } |
| | | |
| | | // 中间检测值添加 |
| | | for (int i = 0; i < sampleList.size(); i++) { |
| | |
| | | |
| | | // 检验项目 |
| | | TextRenderData middleRenderData2 = new TextRenderData(); |
| | | middleRenderData2.setText(sample.getInspectionName()); |
| | | middleRenderData2.setText(sample.getInspectionName()+"∑"+sample.getInspectionName()+i); |
| | | Style middleStyle2 = new Style(); |
| | | middleStyle2.setFontFamily("宋体"); |
| | | middleStyle2.setColor("000000"); |
| | |
| | | TextRenderData middleRenderData6 = new TextRenderData(); |
| | | middleRenderData6.setText((StringUtils.isNotEmpty(sample.getLastValue()) ? |
| | | sample.getLastValue() : "") |
| | | + "∑" + (7 + i)); |
| | | + "∑" + (finalIndex.get() +"_"+ i)); |
| | | Style middleStyle6 = new Style(); |
| | | middleStyle6.setFontFamily("宋体"); |
| | | middleStyle6.setColor("000000"); |
| | |
| | | String type; |
| | | if (count.equals(0)) { |
| | | // 添加不合格描述 |
| | | String item1 = (max == 1 ? "" : "第" + Integer.toString(index) + "次") |
| | | String item1 = (max == 1 ? "" : "第" + index + "次") |
| | | + sample.getInspectionItem() |
| | | + (StringUtils.isBlank(sample.getInspectionItemSubclass()) ? "" : "" + sample.getInspectionItemSubclass()); |
| | | if (resultCh.get().equals("")) { |
| | |
| | | text = new ArrayList<>(); |
| | | } |
| | | |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | |
| | | //设置样式 |
| | | TableStyle tableStyle = new TableStyle(); |
| | | if(max<=5){ |
| | | for (int i = 1; i <= max; i++) { |
| | | // 根据检验结果个数修改长度 |
| | | switch (i) { |
| | | case 1: |
| | | tableStyle.setColWidths(new int[]{650, 2900, 850, 2300, 2100, 1200}); |
| | | break; |
| | | case 2: |
| | | tableStyle.setColWidths(new int[]{650, 2700, 850, 2200, 1200, 1200, 1200}); |
| | | break; |
| | | case 3: |
| | | tableStyle.setColWidths(new int[]{650, 2700, 850, 1600, 1000, 1000, 1000, 1200}); |
| | | break; |
| | | case 4: |
| | | tableStyle.setColWidths(new int[]{650, 2400, 850, 1500, 850, 850, 850, 850, 1200}); |
| | | break; |
| | | case 5: |
| | | tableStyle.setColWidths(new int[]{650, 2200, 850, 1350, 750, 750, 750, 750, 750, 1200}); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | tableStyle.setWidth("10000"); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE); |
| | | borderStyle.setSize(4); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setInsideHBorder(borderStyle); // 设置水平内边框 |
| | | tableStyle.setInsideVBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | |
| | | if (!resultCh.get().equals("")) { |
| | | resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。"); |
| | | } else { |
| | | resultCh.set("经检验此批" + enterFactoryReport.getSample() + "各项目均符合检验规范要求。"); |
| | | } |
| | | |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/small-report-template.docx"); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("report", enterFactoryReport); |
| | | put("standardMethod", standardMethod2.toString().equals("null") ? "" : standardMethod2); |
| | | put("orderType", orderType); |
| | | put("table", tableRenderData); |
| | | put("resultCh", resultCh); |
| | | put("writeUrl", null); |
| | | put("examineUrl", null); |
| | | put("ratifyUrl", null); |
| | | put("writeDateUrl", null); |
| | | put("examineDateUrl", null); |
| | | put("ratifyDateUrl", null); |
| | | put("seal1", null); |
| | | }}); |
| | | try { |
| | | // 修改换行和合并问题 |
| | | updaeMerge(template.getXWPFDocument(), true); |
| | | String name = insReport.getCode().replace("/", "") + "-J.docx"; |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); |
| | | insReport.setUrl("/word/" + name); |
| | | insReport.setIsPass(0); |
| | | insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人 |
| | | insReport.setWriteTime(LocalDateTime.now());//提交时间 |
| | | // 查询报告, 判断之前是否添加过, 添加过删除 |
| | | insReportMapper.delete(Wrappers.<InsReport>lambdaQuery() |
| | | .eq(InsReport::getInsOrderId, insOrder.getId())); |
| | | insReportMapper.insert(insReport); |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加小宝表头 |
| | | * 添加小报告表头 |
| | | * @param text |
| | | * @param max |
| | | * @param rows |
| | | * @return |
| | | */ |
| | | private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows) { |
| | | private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows,List<String> cableTagList) { |
| | | RowRenderData rowRenderData; |
| | | // // 头 |
| | | TextRenderData headRenderData1 = new TextRenderData(); |
| | |
| | | text = new ArrayList<>(); |
| | | |
| | | // 第二行(可能没有) |
| | | if (max > 1) { |
| | | if (max > 1 && CollectionUtil.isEmpty(cableTagList)) { |
| | | TextRenderData tagRenderData1 = new TextRenderData(); |
| | | tagRenderData1.setText(""); |
| | | Style tagStyle1 = new Style(); |
| | |
| | | rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create(); |
| | | rows.add(rowRenderData); |
| | | text = new ArrayList<>(); |
| | | } |
| | | //如果有电缆颜色,生成颜色标识行 |
| | | if(CollectionUtil.isNotEmpty(cableTagList)){ |
| | | TextRenderData tagRenderData1 = new TextRenderData(); |
| | | tagRenderData1.setText(""); |
| | | Style tagStyle1 = new Style(); |
| | | tagStyle1.setFontFamily("宋体"); |
| | | tagStyle1.setColor("000000"); |
| | | tagRenderData1.setStyle(tagStyle1); |
| | | text.add(tagRenderData1); |
| | | |
| | | TextRenderData tagRenderData2 = new TextRenderData(); |
| | | tagRenderData2.setText("绝缘线芯颜色和标志"); |
| | | Style tagStyle2 = new Style(); |
| | | tagStyle2.setFontFamily("宋体"); |
| | | tagStyle2.setColor("000000"); |
| | | tagRenderData2.setStyle(tagStyle2); |
| | | text.add(tagRenderData2); |
| | | |
| | | TextRenderData tagRenderData4 = new TextRenderData(); |
| | | tagRenderData4.setText("/"); |
| | | Style tagStyle4 = new Style(); |
| | | tagStyle4.setFontFamily("宋体"); |
| | | tagStyle4.setColor("000000"); |
| | | tagRenderData4.setStyle(tagStyle4); |
| | | text.add(tagRenderData4); |
| | | |
| | | TextRenderData tagRenderData5 = new TextRenderData(); |
| | | tagRenderData5.setText("/"); |
| | | Style tagStyle5 = new Style(); |
| | | tagStyle5.setFontFamily("宋体"); |
| | | tagStyle5.setColor("000000"); |
| | | tagRenderData5.setStyle(tagStyle5); |
| | | text.add(tagRenderData5); |
| | | |
| | | for (String cableTag : cableTagList) { |
| | | TextRenderData tagRenderData6 = new TextRenderData(); |
| | | tagRenderData6.setText(cableTag); |
| | | Style tagStyle6 = new Style(); |
| | | tagStyle6.setFontFamily("宋体"); |
| | | tagStyle6.setColor("000000"); |
| | | tagRenderData6.setStyle(tagStyle6); |
| | | text.add(tagRenderData6); |
| | | } |
| | | TextRenderData tagRenderData7 = new TextRenderData(); |
| | | tagRenderData7.setText("/"); |
| | | Style tagStyle7 = new Style(); |
| | | tagStyle7.setFontFamily("宋体"); |
| | | tagStyle7.setColor("000000"); |
| | | tagRenderData7.setStyle(tagStyle7); |
| | | text.add(tagRenderData7); |
| | | |
| | | TextRenderData[] text4 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create(); |
| | | rows.add(rowRenderData); |
| | | text = new ArrayList<>(); |
| | | } |
| | | |
| | | return text; |