| | |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.ParseException; |
| | |
| | | @Resource |
| | | private ECRMapper mapper; |
| | | |
| | | public Response ecrImportByExcel(InputStream inputStream) throws IOException, InvalidFormatException, ParseException { |
| | | @Transactional |
| | | public Response ecrImportByExcel(MultipartFile multipartFile) throws IOException, InvalidFormatException, ParseException { |
| | | InputStream inputStream = multipartFile.getInputStream(); |
| | | //存储excel |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | Date date = new Date(); |
| | | String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date); |
| | | //存储路径 |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String excelDir = rootFile + "ecr"; |
| | | File excelDirFile = new File(excelDir); |
| | | if(!excelDirFile.exists()){ |
| | | excelDirFile.mkdirs(); |
| | | } |
| | | String excelFilePath = excelDir + File.separator + originalFilename.substring(0,originalFilename.lastIndexOf(".")) + "_" + dateUnion +originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | String excelHttpUrl = excelFilePath.substring(excelDir.lastIndexOf("doc_file"+ File.separator + "ecr")); |
| | | multipartFile.transferTo(new File(excelFilePath)); |
| | | |
| | | int a = 0; |
| | | int b = 3/a; |
| | | Workbook workbook = null; |
| | | workbook = WorkbookFactory.create(inputStream); |
| | | inputStream.close(); |
| | |
| | | String proposerCellValue = sheet.getRow(2).getCell(22).getStringCellValue(); |
| | | //申请人:xxx |
| | | String proposer = proposerCellValue.substring(4).trim(); |
| | | |
| | | String parentModel = sheet.getRow(3).getCell(0).getStringCellValue().substring(10).trim(); |
| | | |
| | | String changeDescriptionCellValue = sheet.getRow(4).getCell(0).getStringCellValue(); |
| | | |
| | |
| | | } |
| | | } |
| | | String changeType = changeTypeBuilder.toString(); |
| | | String changeDescription = changeDescriptionCellValue + "\n"+changeType; |
| | | String changeDescription = changeDescriptionCellValue + "\n变更原因类别:"+changeType; |
| | | |
| | | //处理方式,处理方式: |
| | | //□1.报废. □2. 用完为止 □3. 重工(变) |
| | |
| | | ecr.setProposer(proposer); |
| | | ecr.setChangeDescription(changeDescription); |
| | | ecr.setSolution(solution); |
| | | ecr.setCreateTime(new Date()); |
| | | ecr.setCreateTime(date); |
| | | ecr.setExcelFile(excelHttpUrl); |
| | | ecr.setParentModel(parentModel); |
| | | //赋值给具体对象 |
| | | for (int i = 0; i < codeSplit.length; i++) { |
| | | ECR ecrTemp = new ECR(); |
| | | BeanUtils.copyProperties(ecr,ecrTemp); |
| | | ecrTemp.setCode(CommonUtil.codeAutoFill(codeSplit[i])); |
| | | ecrTemp.setModel(modelSplit[i]); |
| | | ecrTemp.setSubCode(CommonUtil.codeAutoFill(codeSplit[i])); |
| | | ecrTemp.setSubModel(modelSplit[i]); |
| | | ecrList.add(ecrTemp); |
| | | } |
| | | mapper.insertBatchSomeColumn(ecrList); |