| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.lang.UUID; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.deepoove.poi.data.*; |
| | | import com.deepoove.poi.data.style.*; |
| | | import com.deepoove.poi.util.TableTools; |
| | | import com.deepoove.poi.xwpf.WidthScalePattern; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.ExcelDto; |
| | | import com.yuanchu.mom.dto.InsOrderPlanDTO; |
| | | import com.yuanchu.mom.dto.SampleProductDto; |
| | | 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.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.InsOrderPlanTaskSwitchVo; |
| | | import com.yuanchu.mom.vo.InsOrderPlanVO; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import com.yuanchu.mom.vo.ProductVo; |
| | | import com.yuanchu.mom.vo.SampleVo; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | private InsBushingService insBushingService; |
| | | |
| | | @Resource |
| | | private InsBushingMapper insBushingMapper; |
| | | |
| | | @Resource |
| | | private InsFiberMapper insFiberMapper; |
| | | |
| | | @Resource |
| | | private InsFibersMapper insFibersMapper; |
| | | |
| | | @Resource |
| | | private InsOrderFileMapper insOrderFileMapper; |
| | |
| | | Map<String, Object> map = insOrderService.getInsOrderAndSample(id, laboratory); |
| | | List<SampleProductDto> list = JSON.parseArray(JSON.toJSONString(map.get("sampleProduct")), SampleProductDto.class); |
| | | for (SampleProductDto samples : list) { |
| | | // Set<Integer> set = new HashSet<>(); |
| | | // Map<Integer, String> map2 = new HashMap<>(); |
| | | if (BeanUtil.isEmpty(samples.getInsProduct())) continue; |
| | | samples.setBushing(insBushingService.selectBushingBySampleId(samples.getId())); |
| | | // getTemplateThing(set, map2, samples.getInsProduct()); |
| | | } |
| | | map.put("sampleProduct", list); |
| | | return map; |
| | |
| | | } |
| | | } |
| | | |
| | | //切换记录模版查询检验内容 |
| | | @Override |
| | | public Map<String, Object> getReportModel(Integer sampleId) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //先查出套管 |
| | | List<InsBushing> insBushings = insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery().eq(InsBushing::getInsSampleId, sampleId)); |
| | | List<InsFibers> fibers = new ArrayList<>(); |
| | | List<InsFiber> fiber = new ArrayList<>(); |
| | | for (InsBushing insBushing : insBushings) { |
| | | //再查询出所有的光纤带 |
| | | List<InsFibers> insFibers = insFibersMapper.selectList(Wrappers.<InsFibers>lambdaQuery().eq(InsFibers::getInsBushingId, insBushing.getId())); |
| | | if (CollectionUtils.isNotEmpty(insFibers)) { |
| | | fibers.addAll(insFibers); |
| | | //查出光纤带下所有的光纤 |
| | | List<InsFiber> fiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().in(InsFiber::getInsFibersId, insFibers.stream().map(InsFibers::getId).collect(Collectors.toList()))); |
| | | fiber.addAll(fiberList); |
| | | } else { |
| | | //如果套管下没有光纤带就只有光纤了 |
| | | List<InsFiber> insFiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsBushingId, insBushing.getId())); |
| | | fiber.addAll(insFiberList); |
| | | } |
| | | } |
| | | map.put("光纤带", fibers); |
| | | map.put("光纤", fiber); |
| | | return map; |
| | | } |
| | | |
| | | //温度循环查看列表数据(包括通过样品id,循环次数,温度,循环次数进行筛选) |
| | | @Override |
| | | public Map<String, Object> temCycle(Integer sampleId, String inspectionItem, String inspectionItemSubclass) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //样品信息 |
| | | SampleVo sampleVo = insSampleMapper.getDetailById(sampleId); |
| | | map.put("sampleVo", sampleVo); |
| | | List<ProductVo> productVos = new ArrayList<>(); |
| | | //先查出这个样品下有哪些管色标,光纤带,光纤色标 |
| | | //先查出套管 |
| | | List<InsBushing> insBushings = insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery().eq(InsBushing::getInsSampleId, sampleId)); |
| | | for (InsBushing insBushing : insBushings) { |
| | | //再查询出所有的光纤带 |
| | | List<InsFibers> insFibers = insFibersMapper.selectList(Wrappers.<InsFibers>lambdaQuery().eq(InsFibers::getInsBushingId, insBushing.getId())); |
| | | if (CollectionUtils.isNotEmpty(insFibers)) { |
| | | for (InsFibers insFiber : insFibers) { |
| | | //查出光纤带下所有的光纤 |
| | | List<InsFiber> fiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsFibersId, insFiber.getId())); |
| | | for (InsFiber fiber : fiberList) { |
| | | //再根据关联的光纤配置的id和循环次数和温度和样品id进行查询检验项目 |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, sampleId) |
| | | .eq(InsProduct::getInspectionItem, inspectionItem) |
| | | .eq(InsProduct::getInspectionItemSubclass, inspectionItemSubclass) |
| | | .eq(InsProduct::getInsFiberId, fiber.getId())); |
| | | for (InsProduct insProduct : insProducts) { |
| | | InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); |
| | | ProductVo productVo = new ProductVo(); |
| | | productVo.setCode(insFiber.getCode()); |
| | | productVo.setColor(fiber.getColor()); |
| | | productVo.setBushColor(fiber.getBushColor()); |
| | | if (ObjectUtils.isNotEmpty(insProductResult)) { |
| | | insProduct.setInsProductResult(insProductResult); |
| | | } |
| | | productVo.setInsProduct(insProduct); |
| | | productVos.add(productVo); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | //如果套管下没有光纤带就只有光纤了 |
| | | List<InsFiber> insFiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsBushingId, insBushing.getId())); |
| | | for (InsFiber fiber : insFiberList) { |
| | | //再根据关联的光纤配置的id和循环次数和温度和样品id进行查询检验项目 |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, sampleId) |
| | | .eq(InsProduct::getInspectionItem, inspectionItem) |
| | | .eq(InsProduct::getInspectionItemSubclass, inspectionItemSubclass) |
| | | .eq(InsProduct::getInsFiberId, fiber.getId())); |
| | | for (InsProduct insProduct : insProducts) { |
| | | InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); |
| | | ProductVo productVo = new ProductVo(); |
| | | productVo.setCode("/"); |
| | | productVo.setColor(fiber.getColor()); |
| | | productVo.setBushColor(fiber.getBushColor()); |
| | | insProduct.setInsProductResult(insProductResult); |
| | | productVo.setInsProduct(insProduct); |
| | | productVos.add(productVo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | map.put("productVos", productVos); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void saveInsContext(Map<String, Object> insContext) { |
| | | Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); |
| | |
| | | JSONObject jo = JSON.parseObject(JSON.toJSONString(v)); |
| | | InsProduct insProduct = new InsProduct(); |
| | | insProduct.setId(Integer.parseInt(k)); |
| | | InsProductResult result = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); |
| | | if (BeanUtil.isEmpty(result)) { |
| | | List<InsProductResult> results = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); |
| | | InsProductResult result; |
| | | if (CollectionUtils.isEmpty(results)) { |
| | | result = new InsProductResult(); |
| | | } else { |
| | | result = results.get(0); |
| | | } |
| | | result.setInsProductId(Integer.parseInt(k)); |
| | | if (jo.get("insValue") != null) { |
| | |
| | | .eq(AuxiliaryOutputWorkingHours::getCheck, userId) |
| | | .eq(AuxiliaryOutputWorkingHours::getInspectProject, insProduct.getInspectionItemSubclass() + insProduct.getInspectionItem()) |
| | | .eq(AuxiliaryOutputWorkingHours::getOrderNo, insOrder.getEntrustCode())); |
| | | if (count == 0) { |
| | | if (count == 0 && ObjectUtils.isNotEmpty(insProduct.getManHour())) { |
| | | //添加每个人的产量工时 |
| | | AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours(); |
| | | auxiliaryOutputWorkingHours.setInspectProject(insProduct.getInspectionItemSubclass() + insProduct.getInspectionItem());//检测项目 |
| | |
| | | for (InsProduct insProduct : insProducts) { |
| | | if (insProduct.getInsResult() == 0) { |
| | | InsUnPass insUnPass = new InsUnPass(); |
| | | insUnPass.setId(null); |
| | | insUnPass.setModel(insSample.getModel()); |
| | | insUnPass.setSample(insSample.getSample()); |
| | | insUnPass.setInspectionItem(insProduct.getInspectionItem()); |
| | |
| | | insUnPasses.add(insUnPass); |
| | | } |
| | | } |
| | | insUnPassService.saveBatch(insUnPasses); |
| | | } |
| | | insUnPassService.saveBatch(insUnPasses); |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId()); |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(insOrder.getEntrustCode()); |
| | | insReport.setInsOrderId(orderId); |
| | | Set<Integer> set = new HashSet<>(); |
| | | Map<Integer, String> map2 = new HashMap<>(); |
| | | List<Map<String, Object>> tables = new ArrayList<>(); |
| | | Set<String> standardMethod = new HashSet<>(); |
| | | Set<String> deviceSet = new HashSet<>(); |
| | |
| | | AtomicReference<String> resultCh = new AtomicReference<>(""); |
| | | AtomicReference<String> resultEn = new AtomicReference<>(""); |
| | | samples.forEach(a -> { |
| | | Set<Integer> set = new HashSet<>(); |
| | | Map<Integer, String> map2 = new HashMap<>(); |
| | | Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, a.getId())); |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | models.add(a.getModel()); |
| | |
| | | } |
| | | templateSet.add(JSON.toJSONString(b.getTemplate())); |
| | | } |
| | | AtomicInteger index = new AtomicInteger(); |
| | | Set<String> itemSet = new HashSet<>(); |
| | | templateSet.forEach(tem -> { |
| | | AtomicInteger index = new AtomicInteger(); |
| | | Set<Integer> set2 = new HashSet<>(); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | List<TextRenderData> text = new ArrayList<>(); |
| | |
| | | Set<String> delSet = new HashSet<>(); |
| | | List<ExcelDto> excelDtos = JSON.parseArray(tem, ExcelDto.class); |
| | | List<ExcelDto> mcList = new ArrayList<>(); |
| | | /* int aaaa = excelDtos.get(excelDtos.size() - 1).getR();//这里是模版里面的所有检测项的长度,先以15个项目分页 |
| | | int bbbb = 17; |
| | | int cccc = 0; |
| | | for (int p = 0; p < aaaa; p++) { |
| | | if (p % bbbb == 0) { |
| | | for (int y = 0; y < excelDtos.size(); y++) { |
| | | if (y == 0 || y == 1) { |
| | | if (excelDtos.get(y).getV().getMc() != null && excelDtos.get(y).getV().getMc().getCs() != null && excelDtos.get(y).getV().getMc().getRs() != null) { |
| | | mcList.add(excelDtos.get(y)); |
| | | } |
| | | } else { |
| | | try { |
| | | excelDtos.get(y + cccc - 2); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | if (excelDtos.get(y + cccc - 2).getV().getMc() != null && excelDtos.get(y + cccc - 2).getV().getMc().getCs() != null && excelDtos.get(y + cccc - 2).getV().getMc().getRs() != null) { |
| | | mcList.add(excelDtos.get(y + cccc - 2)); |
| | | } |
| | | } |
| | | } |
| | | cccc += 17; |
| | | } |
| | | }*/ |
| | | excelDtos.forEach(b -> { |
| | | if (b.getV().getMc() != null && b.getV().getMc().getCs() != null && b.getV().getMc().getRs() != null) { |
| | | mcList.add(b); |
| | |
| | | Map<String, InsProduct> pMap = new HashMap<>(); |
| | | Set<String> delRSet = new HashSet<>(); |
| | | delRSet.add("0"); |
| | | delRSet.add("1"); |
| | | for (JSONObject jo1 : temp) { |
| | | JSONObject v = JSON.parseObject(JSON.toJSONString(jo1.get("v"))); |
| | | if (Integer.parseInt(jo1.get("c") + "") > 9) { |
| | |
| | | if (p != null && v.get("ps") != null) { |
| | | String value = JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + ""; |
| | | if (value.equals("要求值")) { |
| | | textRenderData.setText(p.getAsk()); |
| | | textRenderData.setText(ObjectUtils.isNotEmpty(p.getTell()) ? p.getTell() : ""); |
| | | } else if (value.equals("单位")) { |
| | | textRenderData.setText(p.getUnit()); |
| | | } else if (value.equals("结论")) { |
| | |
| | | break; |
| | | } |
| | | } else if (value.equals("序号")) { |
| | | index.getAndIncrement(); |
| | | if (itemSet.add(p.getInspectionItem())) { |
| | | index.getAndIncrement(); |
| | | } |
| | | textRenderData.setText(index + ""); |
| | | } else if (value.equals("计算值")) { |
| | | JSONArray jsonArray = JSON.parseArray(p.getInsProductResult().getComValue()); |
| | |
| | | textRenderData.setText(a.getSample()); |
| | | } else if (value.equals("试验方法")) { |
| | | textRenderData.setText(p.getMethodS()); |
| | | } else if (value.equals("检验项")) { |
| | | textRenderData.setText(p.getInspectionItem() + "&" + p.getInspectionItemEn()); |
| | | } else if (value.equals("检验子项")) { |
| | | if (ObjectUtils.isEmpty(p.getInspectionItemSubclassEn())) { |
| | | textRenderData.setText(p.getInspectionItemSubclass()); |
| | | } else { |
| | | textRenderData.setText(p.getInspectionItemSubclass() + "&" + p.getInspectionItemSubclassEn()); |
| | | } |
| | | } else { |
| | | textRenderData.setText(v.get("v") == null ? "" : v.get("v") + ""); |
| | | } |
| | |
| | | tableRenderData.setRows(rows); |
| | | int countSize = tableRenderData.getRows().get(0).getCells().size(); |
| | | for (RowRenderData row : tableRenderData.getRows()) { |
| | | for (CellRenderData cell : row.getCells()) { |
| | | /*for (CellRenderData cell : row.getCells()) { |
| | | System.out.print(cell.getParagraphs().get(0).getContents()); |
| | | } |
| | | System.out.println(""); |
| | | System.out.println("");*/ |
| | | if (row.getCells().size() != countSize) { |
| | | throw new ErrorException("每行单元格不相等"); |
| | | } |
| | |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | List<Map<String, String>> finalDeviceList = deviceList; |
| | | Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, orderId).orderByDesc(InsSampleUser::getCreateTime).last("limit 1")).getUserId(); |
| | | Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, orderId).last("limit 1")).getUserId(); |
| | | String signatureUrl; |
| | | try { |
| | | signatureUrl = userMapper.selectById(userId).getSignatureUrl(); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("找不到检验人的签名"); |
| | | } |
| | | Custom custom = customMapper.selectById(user.get("company")); |
| | | //Custom custom = customMapper.selectById(user.get("company")); |
| | | Custom custom = customMapper.selectById(insOrder.getCompanyId()); |
| | | if (!resultCh.get().equals("")) { |
| | | resultCh.set("依据委托要求," + resultCh.get().replaceFirst("、", "") + "等所检项目不符合要求,其余所检项目均符合要求。"); |
| | | resultEn.set("According to commissioned requirements," + resultEn.get().replaceFirst("、", "") + " these inspected items do not meet the requirements, all other inspected items meet the requirements."); |
| | |
| | | List<InsProduct> insProducts1 = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, sample.getId()) |
| | | .isNotNull(InsProduct::getInsFiberId)); |
| | | long size = insProducts1.size(); |
| | | .isNotNull(InsProduct::getInsFiberId) |
| | | .isNull(InsProduct::getInspectionItemClass)); |
| | | List<InsProduct> filteredProducts = insProducts1.stream() |
| | | .collect(Collectors.groupingBy(product -> product.getInspectionItem() + product.getInspectionItemSubclass())) |
| | | .values().stream() |
| | | .map(group -> group.get(0)) |
| | | .sorted(Comparator.comparing(InsProduct::getInspectionItem)) |
| | | .collect(Collectors.toList()); |
| | | long size = insProducts1.stream().map(insProduct -> { |
| | | return (insProduct.getInspectionItem() + insProduct.getInspectionItemSubclass()); |
| | | }).distinct().collect(Collectors.toList()).size(); |
| | | long size2 = insProducts1.stream().map(InsProduct::getInsFiberId).distinct().count(); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | //判断检验项目是否有父子关系 |
| | | Boolean state = true; |
| | | for (InsProduct insProduct : insProducts1) { |
| | | if (!insProduct.getInspectionItemSubclass().equals("") && insProduct.getInspectionItemSubclass() != null) { |
| | | state = false; |
| | | } |
| | | } |
| | | int a = 1; |
| | | if (!state) { |
| | | a = 2; |
| | | } |
| | | //表格的行数 |
| | | for (long i = 0; i < size2 + a; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //表格的列数 |
| | | for (long j = 0; j < size + 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("管色标\nPipe∑100"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("光纤色标\nScanning Number∑101"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | textRenderData.setText(insProducts1.get((int) (j - 2)).getInspectionItem() + "\n" + insProducts1.get((int) (j - 2)).getInspectionItemEn()+"∑"+(j+101)); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else if (a == 2 && i == 1) { |
| | | //有父子项目关系的第三行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText("管色标\nPipe∑100"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("光纤色标\tScanning Number∑101"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | //判断是否有项目子类 |
| | | if (insProducts1.get((int) (j - 2)).getInspectionItemSubclass().equals("") || insProducts1.get((int) (j - 2)).getInspectionItemSubclass() == null) { |
| | | textRenderData.setText(insProducts1.get((int) (j - 2)).getInspectionItem() + "\n" + insProducts1.get((int) (j - 2)).getInspectionItemEn()+"∑"+(j+101)); |
| | | } else { |
| | | textRenderData.setText(insProducts1.get((int) (j - 2)).getInspectionItemSubclass() + "\n" + insProducts1.get((int) (j - 2)).getInspectionItemSubclassEn()); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else { |
| | | int aa = 0; |
| | | if (a == 2) { |
| | | aa = (int) i - 2; |
| | | } else aa = (int) i - 1; |
| | | InsFiber insFiber = insFiberMapper.selectById(insProducts1.get(aa).getInsFiberId()); |
| | | //填值 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText(insFiber.getBushColor()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText(insFiber.getColor()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | textRenderData.setText(insProducts1.get((int) (j - 2)).getLastValue()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | long number = 7; |
| | | long k = 0; |
| | | for (long c = 0; c < size; c++) { |
| | | if (c % number == 0) { |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | //判断检验项目是否有父子关系 |
| | | Boolean state = true; |
| | | for (InsProduct insProduct : filteredProducts) { |
| | | if (!insProduct.getInspectionItemSubclass().equals("") && insProduct.getInspectionItemSubclass() != null) { |
| | | state = false; |
| | | } |
| | | } |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | if (rowRenderData.getCells().size() != 0) { |
| | | rows.add(rowRenderData); |
| | | int a = 1; |
| | | if (!state) { |
| | | a = 2; |
| | | } |
| | | //表格的行数 |
| | | for (long i = 0; i < size2 + a; i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //表格的列数 |
| | | for (long j = 0; j < 9; 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("管色标&Pipe∑100"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("光纤色标&Scanning Number∑101"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | try { |
| | | filteredProducts.get((int) (j - 2 + k)); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | textRenderData.setText(filteredProducts.get((int) (j - 2 + k)).getInspectionItem() + "&" + insProducts1.get((int) (j - 2 + k)).getInspectionItemEn() + "∑" + (j + 101 + k)); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else if (a == 2 && i == 1) { |
| | | //有父子项目关系的第三行 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText("管色标&Pipe∑100"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("光纤色标&Scanning Number∑101"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | try { |
| | | filteredProducts.get((int) (j - 2 + k)); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | //判断是否有项目子类 |
| | | if (filteredProducts.get((int) (j - 2 + k)).getInspectionItemSubclass().equals("") || filteredProducts.get((int) (j - 2 + k)).getInspectionItemSubclass() == null) { |
| | | textRenderData.setText(filteredProducts.get((int) (j - 2 + k)).getInspectionItem() + "&" + filteredProducts.get((int) (j - 2 + k)).getInspectionItemEn() + "∑" + (j + 101 + k)); |
| | | } else { |
| | | textRenderData.setText(filteredProducts.get((int) (j - 2 + k)).getInspectionItemSubclass() + "&" + filteredProducts.get((int) (j - 2 + k)).getInspectionItemSubclassEn()); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | } else { |
| | | int aa; |
| | | if (a == 2) { |
| | | aa = (int) i - 2; |
| | | } else aa = (int) i - 1; |
| | | List<Integer> list = insProducts1.stream().map(InsProduct::getInsFiberId).distinct().collect(Collectors.toList()); |
| | | try { |
| | | insFiberMapper.selectById(list.get(aa)); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | InsFiber insFiber = insFiberMapper.selectById(list.get(aa)); |
| | | //填值 |
| | | if (j == 0) { |
| | | //第一列 |
| | | textRenderData.setText(insFiber.getBushColor()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText(insFiber.getColor()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //项目信息 |
| | | try { |
| | | filteredProducts.get((int) (j - 2 + k)); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | textRenderData.setText(filteredProducts.get((int) (j - 2 + k)).getLastValue()); |
| | | 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()) { |
| | | for (CellRenderData cell : row.getCells()) { |
| | | System.out.print(cell.getParagraphs().get(0).getContents()); |
| | | } |
| | | System.out.println(""); |
| | | 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(14); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | Map<String, Object> table = new HashMap<>(); |
| | | table.put("table2", tableRenderData); |
| | | table.put("report", insReport); |
| | | table.put("sample_number", sample.getSampleCode()); |
| | | table.put("type", sample.getModel()); |
| | | tables2.add(table); |
| | | k += 7; |
| | | } |
| | | } |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | int countSize = tableRenderData.getRows().get(0).getCells().size(); |
| | | for (RowRenderData row : tableRenderData.getRows()) { |
| | | for (CellRenderData cell : row.getCells()) { |
| | | System.out.print(cell.getParagraphs().get(0).getContents()); |
| | | } |
| | | System.out.println(""); |
| | | 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(14); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | Map<String, Object> table = new HashMap<>(); |
| | | table.put("table2", tableRenderData); |
| | | table.put("report", insReport); |
| | | table.put("sample_number",sample.getSampleCode() ); |
| | | table.put("type", sample.getModel()); |
| | | tables2.add(table); |
| | | }); |
| | | } |
| | | |
| | | |
| | | /*获取附件图片类型*/ |
| | | 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, samples.get(0).getId())).get(0); |
| | | String environment = ""; |
| | | environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "℃ " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : ""); |
| | | String finalEnvironment = environment; |
| | | XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("order", insOrder); |
| | | put("report", insReport); |
| | | put("user", user); |
| | | put("environment", finalEnvironment); |
| | | put("custom", custom); |
| | | put("sampleSize", samples.size()); |
| | | put("tables", tables); |
| | |
| | | put("insTimeEn", monthNames[insOrder.getInsTime().getMonthValue() - 1] + " " + now.getDayOfMonth() + ", " + now.getYear()); |
| | | put("writeUrl", null); |
| | | put("insUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); |
| | | put("images", images); |
| | | put("examineUrl", null); |
| | | put("ratifyUrl", null); |
| | | put("sampleEn", sampleEn); |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //处理合并单元格的问题 |
| | | String path = wordUrl + "/" + insReport.getCode().replace("/", "") + ".docx"; |
| | | try { |
| | | FileInputStream stream = new FileInputStream(path); |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | try { |
| | | 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 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("&")) { |
| | | String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); |
| | | String[] split = text.split("&"); |
| | | xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); |
| | | XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); |
| | | XWPFRun run = xwpfParagraph.createRun(); |
| | | run.setText(split[0]); |
| | | if (ObjectUtils.isNotNull(split[1])) { |
| | | run.addBreak(); |
| | | run.setText(split[1]); |
| | | } |
| | | xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //处理检验结果跨页的问题 |
| | | FileOutputStream fileOutputStream1 = new FileOutputStream(path); |
| | | document1.write(fileOutputStream1); |
| | | fileOutputStream1.close(); |
| | | } catch (FileNotFoundException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | private void getTemplateThing(Set<Integer> set, Map<Integer, String> map2, List<InsProduct> insProducts) { |
| | | private void getTemplateThing |
| | | (Set<Integer> set, Map<Integer, String> map2, List<InsProduct> insProducts) { |
| | | for (InsProduct product : insProducts) { |
| | | if (product.getTemplateId() == null) { |
| | | product.setTemplate(new ArrayList<>()); |
| | |
| | | String str = ""; |
| | | int count = 0; |
| | | for (InsProduct product : insProducts) { |
| | | count++; |
| | | str += "<br/>" + count + ":" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>"; |
| | | //如果是光缆的温度循环 |
| | | if (product.getInspectionItem().equals("温度循环") && insOrderMapper.selectById(orderId).getSampleType().equals("光缆")) { |
| | | //查询那些循环温度的检验项目的结论是否全部检验 |
| | | List<InsProduct> insProductList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, product.getInsSampleId()) |
| | | .isNotNull(InsProduct::getInsFiberId).like(InsProduct::getInspectionItemSubclass, "℃")); |
| | | List<Integer> collect = insProductList.stream().filter(insProduct -> insProduct.getInsResult() != null).map(InsProduct::getInsResult).collect(Collectors.toList()); |
| | | List<Integer> tt = new ArrayList<>(); |
| | | tt.add(1); |
| | | if (collect.contains(0)) { |
| | | product.setInsResult(0); |
| | | } else if (collect.size() == insProductList.size() && collect.stream().distinct().collect(Collectors.toList()).containsAll(tt)) { |
| | | product.setInsResult(0); |
| | | } |
| | | insProductMapper.updateById(product); |
| | | } else { |
| | | count++; |
| | | str += "<br/>" + count + ":" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>"; |
| | | } |
| | | } |
| | | throw new ErrorException("<strong>存在待检验的项目:</strong><br/>" + str); |
| | | } |