| | |
| | | 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; |
| | | |
| | | /** |
| | | * 检验任务-业务实现层 |
| | |
| | | dianLuUtils.readDianLuFile2(sampleId, insOrderFile); |
| | | } else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验") && split[split.length - 1].equals("csv") && insOrder.getSampleType().equals("无源器件")) { |
| | | dianLuUtils.readDianLuFile3(sampleId, insOrderFile); |
| | | } |
| | | // 震动doc文件解析 |
| | | if(filename.contains(".doc") && sonLaboratory.equals("振动")){ |
| | | return docAnalysis(urlString,orderId,sampleId,file.getOriginalFilename()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ErrorException(e.getMessage()); |
| | |
| | | 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++) { |
| | | 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() > 0){ |
| | | 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++) { |
| | | 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) { |