| | |
| | | import com.yuanchu.mom.service.*; |
| | | import com.yuanchu.mom.utils.*; |
| | | import com.yuanchu.mom.vo.*; |
| | | import org.apache.poi.hwpf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.CellValue; |
| | | import org.apache.poi.xssf.usermodel.XSSFCell; |
| | | import org.apache.poi.xssf.usermodel.XSSFRow; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.apache.poi.hwpf.HWPFDocument; |
| | | |
| | | /** |
| | | * 检验任务-业务实现层 |
| | |
| | | } else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验") && split[split.length - 1].equals("csv") && insOrder.getSampleType().equals("无源器件")) { |
| | | dianLuUtils.readDianLuFile3(sampleId, insOrderFile); |
| | | } |
| | | // 电路实验返回文件名 |
| | | if(ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验")){ |
| | | return pathName; |
| | | } |
| | | // 震动doc文件解析 |
| | | if(filename.toLowerCase().contains(".doc") && sonLaboratory.equals("振动")){ |
| | | return docAnalysis(urlString,orderId,sampleId,file.getOriginalFilename()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | |
| | | if (orderState.getInsState() == 6) { |
| | | orderState.setInsState(0); |
| | | orderState.setNum(orderState.getNum() + 1);//递增 |
| | | orderState.setCreateTime(LocalDateTime.now()); |
| | | insOrderStateMapper.updateById(orderState); |
| | | } |
| | | } else { |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | result.setAfterCheck("");//'' |
| | | } |
| | | //实验结果 |
| | | try { |
| | | JSONObject resValue = JSON.parseObject(JSON.toJSONString(jo.get("testResult"))); |
| | | if (resValue.get("v") != null) { |
| | | Object o = JSON.parseObject(JSON.toJSONString(resValue.get("v"))).get("v"); |
| | | result.setTestResult(o.equals("") ? null : (o.toString())); |
| | | } |
| | | } catch (Exception e) { |
| | | result.setTestResult("");//'' |
| | | } |
| | | //设备编号 |
| | | if (jo.get("equipValue") != null) { |
| | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 震动doc文件解析 |
| | | * @param urlString |
| | | * @param orderId |
| | | * @param sampleId |
| | | * @param originFileName |
| | | * @return |
| | | */ |
| | | private Map<String, String> docAnalysis(String urlString,Integer orderId,Integer sampleId,String originFileName) { |
| | | Map<String, String> analysisMap = new HashMap<>(); |
| | | try { |
| | | File file = new File(urlString); |
| | | HWPFDocument document = new HWPFDocument(new FileInputStream(file)); |
| | | Range range = document.getRange(); |
| | | TableIterator tableIterator = new TableIterator(range); |
| | | List<Table> tableList = new ArrayList<>(); |
| | | while (tableIterator.hasNext()) { |
| | | tableList.add(tableIterator.next()); |
| | | } |
| | | for (int tableIndex = 0; tableIndex < tableList.size(); tableIndex++) { |
| | | // 取第一个表单限制参数的 振动台型号、运动部件等效质量、试件质量数值 |
| | | if(tableIndex == 0){ |
| | | Table table = tableList.get(0); |
| | | for (int i = 0; i < table.numRows(); i++) { |
| | | if(table.getRow(i).numCells() < 2){ |
| | | continue; |
| | | } |
| | | String columnText = ObjectUtils.isEmpty(table.getRow(i).getCell(0))? "" : table.getRow(i).getCell(0).text(); |
| | | String columnValue = ObjectUtils.isEmpty(table.getRow(i).getCell(1))? "" : table.getRow(i).getCell(1).text(); |
| | | if(columnValue.contains("\u0007")){ |
| | | columnValue = columnValue.replace("\u0007",""); |
| | | } |
| | | if(columnText.contains("\u0007")){ |
| | | columnText = columnText.replace("\u0007",""); |
| | | } |
| | | if(columnText.equals("振动台型号")){ |
| | | analysisMap.put("11",columnValue); |
| | | } |
| | | if(columnText.equals("运动部件等效质量")){ |
| | | analysisMap.put("12",columnValue); |
| | | } |
| | | if(columnText.equals("试件质量")){ |
| | | analysisMap.put("1",columnValue); |
| | | } |
| | | } |
| | | } |
| | | //取第一个表单输入通道参数第一条数据 |
| | | if(tableIndex == 1){ |
| | | Table table = tableList.get(1); |
| | | if(ObjectUtils.isNotEmpty(table) && table.numRows() > 1 && table.getRow(1).numCells() >= 3){ |
| | | String columnValue = ObjectUtils.isEmpty(table.getRow(1).getCell(2))? "" : table.getRow(1).getCell(2).text(); |
| | | if(columnValue.contains("\u0007")){ |
| | | columnValue = columnValue.replace("\u0007",""); |
| | | } |
| | | analysisMap.put("9",columnValue); |
| | | } |
| | | } |
| | | // 取最后一个表单第三第四行信息 |
| | | if(tableIndex == tableList.size() - 1){ |
| | | Table table = tableList.get(tableIndex); |
| | | for (int i = 0; i < table.numRows(); i++) { |
| | | if(table.getRow(i).numCells() < 2){ |
| | | continue; |
| | | } |
| | | String columnText = ObjectUtils.isEmpty(table.getRow(i).getCell(0))? "" : table.getRow(i).getCell(0).text(); |
| | | String columnValue = ObjectUtils.isEmpty(table.getRow(i).getCell(1))? "" : table.getRow(i).getCell(1).text(); |
| | | if(columnValue.contains("\u0007")){ |
| | | columnValue = columnValue.replace("\u0007",""); |
| | | } |
| | | if(columnText.contains("\u0007")){ |
| | | columnText = columnText.replace("\u0007",""); |
| | | } |
| | | if(columnText.contains("总运行时间")){ |
| | | analysisMap.put("13",columnValue); |
| | | } |
| | | if(columnText.contains("试验扫频数")){ |
| | | analysisMap.put("10",columnValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 图片绑定 |
| | | List<Picture> pictureList = document.getPicturesTable().getAllPictures(); |
| | | String[] split = originFileName.split("\\."); |
| | | String docName = ""; |
| | | if(null != split && split.length > 0){ |
| | | docName = split[0]; |
| | | } |
| | | for (Picture picture : pictureList) { |
| | | byte[] pictureData = picture.getContent(); |
| | | File imgDir = new File(imgUrl); |
| | | if (!imgDir.exists()) { |
| | | imgDir.mkdirs(); |
| | | } |
| | | String filename = docName + "_" + UUID.randomUUID()+".png"; |
| | | File pictureFile = new File(imgUrl + File.separatorChar + filename); |
| | | // 创建输出流以将图片数据写入到指定路径 |
| | | try (OutputStream outputStream = new FileOutputStream(pictureFile)) { |
| | | // 写入数据 |
| | | outputStream.write(pictureData); |
| | | } |
| | | InsOrderFile insOrderFile = new InsOrderFile(); |
| | | insOrderFile.setInsOrderId(orderId); |
| | | insOrderFile.setInsSampleId(sampleId); |
| | | insOrderFile.setSonLaboratory("振动"); |
| | | insOrderFile.setType(1); |
| | | insOrderFile.setFileName(filename); |
| | | insOrderFile.setFileUrl(filename); |
| | | insOrderFileMapper.insert(insOrderFile); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | } |
| | | return analysisMap; |
| | | } |
| | | |
| | | //温湿度试验+功率试验的保存检验内容 |
| | | @Override |
| | | public int saveInsContext3(InsProductResult insProductResult) { |
| | |
| | | } |
| | | } |
| | | // 处理其他比较条件 |
| | | if (ask.startsWith(">")) { |
| | | if (ask.startsWith(">") || ask.startsWith(">")) { |
| | | double threshold = Double.parseDouble(ask.substring(1)); |
| | | return s > threshold; |
| | | } else if (ask.startsWith("≥")) { |
| | | double threshold = Double.parseDouble(ask.substring(1)); |
| | | return s >= threshold; |
| | | } else if (ask.startsWith("<")) { |
| | | } else if (ask.startsWith("<")|| ask.startsWith("<")) { |
| | | double threshold = Double.parseDouble(ask.substring(1)); |
| | | return s < threshold; |
| | | } else if (ask.startsWith("≤")) { |
| | | double threshold = Double.parseDouble(ask.substring(1)); |
| | | return s <= threshold; |
| | | } else if (ask.equals("=")) { |
| | | } else if (ask.equals("=")|| ask.startsWith("=")) { |
| | | double exactValue = Double.parseDouble(ask.substring(1)); |
| | | return s == exactValue; |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int verifyPlan(Integer sampleId, String laboratory, Integer type, String tell) throws IOException { |
| | | public int verifyPlan(Integer sampleId, String laboratory, Integer type, String tell) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); |
| | | List<InsUnPass> insUnPasses = new ArrayList<>(); |
| | |
| | | //如果订单类型是原理样机,则该订单直接闭环 |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insSample.getInsOrderId())); |
| | | for (InsSample sample : insSamples) { |
| | | outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode()); |
| | | try{ |
| | | outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode()); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | /*生成对应的检验报告*/ |
| | | List<InsReportDto1> insReportDto1s=insOrderUserMapper.selectInsReportDto1(insOrder.getId()); |
| | | createReport(insOrder.getId(),insReportDto1s); |
| | | //该订单闭环 |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | break; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int verifyPlan2(Integer sampleId, String laboratory, Integer type, String tell) throws IOException { |
| | | public int verifyPlan2(Integer sampleId, String laboratory, Integer type, String tell) { |
| | | Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); |
| | | InsSample insSample = insSampleMapper.selectById(sampleId); |
| | | InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); |
| | |
| | | .orderByDesc(InsOrderState::getId) |
| | | .last("LIMIT 1")); // 确保只取一条记录 |
| | | if (record != null) { |
| | | //更新记录 |
| | | insOrderUserMapper.update(null, Wrappers.<InsOrderUser>lambdaUpdate() |
| | | .eq(InsOrderUser::getInsOrderStateId, record.getId()) |
| | | .eq(InsOrderUser::getNum, record.getNum()) |
| | | .set(InsOrderUser::getTell, tell)); |
| | | switch (type) { |
| | | case 0: |
| | | //再次试验:该单子退回到检验状态(排序改成当前的最后),次数递增(保留以前的数据); |
| | |
| | | .set(InsOrderState::getVerifyUser, userId) |
| | | .set(InsOrderState::getNum, record.getNum() + 1)//次数加1 |
| | | .set(InsOrderState::getCreateTime, LocalDateTime.now())); |
| | | insOrder.setState(3); |
| | | break; |
| | | case 1: |
| | | //继续试验:该样品该站点任务结束(可以再次扫码检验); |
| | |
| | | .set(InsOrderState::getVerifyTell, tell) |
| | | .set(InsOrderState::getVerifyUser, userId)); |
| | | } |
| | | insOrder.setState(3); |
| | | break; |
| | | case 2: |
| | | //结束试验:此委托单停止试验(无法再次检验)。 |
| | |
| | | //出库 |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insSample.getInsOrderId())); |
| | | for (InsSample sample : insSamples) { |
| | | outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode()); |
| | | try{ |
| | | outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode()); |
| | | }catch (Exception e){ |
| | | } |
| | | } |
| | | /*生成对应的检验报告*/ |
| | | List<InsReportDto1> insReportDto1s=insOrderUserMapper.selectInsReportDto1(insOrder.getId()); |
| | | createReport(insOrder.getId(),insReportDto1s); |
| | | //订单闭环 |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | break; |
| | | } |
| | | insOrderMapper.updateById(insOrder); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | /*生成对应的检验报告*/ |
| | | private void createReport(Integer orderId,List<InsReportDto1> insReportDto1s){ |
| | | for (InsReportDto1 insReportDto1 : insReportDto1s) { |
| | | if (ObjectUtils.isNotEmpty(insReportDto1.getInsReportDto2s())){ |
| | | wordUtils.generateReport(orderId, insReportDto1); |
| | | // try{ |
| | | // wordUtils.generateReport(orderId, insReportDto1); |
| | | // }catch (Exception e){ |
| | | // throw new ErrorException("报告格式生成有误,请联系管理员!"); |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void getTemplateThing |
| | |
| | | String str = ""; |
| | | int count = 0; |
| | | for (InsProduct product : insProducts) { |
| | | //辐射试验,温湿度试验,功率试验的检验项目,不需要去手动填写检验值,只需要上传表格文件就可以了,后台提交的时候校验跳过这个检验项目 |
| | | if (product.getInspectionItem().equals("辐射试验") || product.getInspectionItem().equals("温湿度试验") || product.getInspectionItem().equals("功率试验")) { |
| | | //温湿度试验,功率试验的检验项目,不需要去手动填写检验值,只需要上传表格文件就可以了,后台提交的时候校验跳过这个检验项目 |
| | | if ( product.getInspectionItem().equals("温湿度试验") || product.getInspectionItem().equals("功率试验")) { |
| | | product.setInsResult(3);//不判定 |
| | | insProductMapper.updateById(product); |
| | | continue; |