| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ProductBomApprovingMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.ProductBomApproving; |
| | | import com.whyc.pojo.WorksheetMain; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.Zip4jUtil; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.crypto.Data; |
| | |
| | | public void insert(List<ProductBomApproving> bomList) { |
| | | mapper.insertBatchSomeColumn(bomList); |
| | | } |
| | | |
| | | public Response zipParse(MultipartFile file) throws IOException { |
| | | Response response = new Response(); |
| | | //检查是否为zip |
| | | boolean isZip = Zip4jUtil.checkZipFileParam(file); |
| | | if(!isZip){ |
| | | return response.set(1,false,"上传的文件格式不是zip"); |
| | | } |
| | | //zip存储路径:doc_file/product_approving/${username}/{dateFormat}/${timeStamp} |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | DocUser user = ActionUtil.getUser(); |
| | | String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date()); |
| | | long timeStamp = System.currentTimeMillis(); |
| | | String zipPath = rootFile + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp; |
| | | File zipFile = new File(zipPath); |
| | | if(!zipFile.exists()){ |
| | | zipFile.mkdirs(); |
| | | } |
| | | file.transferTo(zipFile); |
| | | //解压文件夹 |
| | | Zip4jUtil.unPackZip(zipFile,null,zipPath); |
| | | //遍历解压后的文件夹路径,解析excel |
| | | System.out.println(zipPath); |
| | | File[] bomFileDirArr = zipFile.listFiles(); |
| | | for (File bomFileDir : bomFileDirArr){ |
| | | String bomFileDirName = bomFileDir.getName(); |
| | | System.out.println(bomFileDirName); |
| | | File[] bomFileArr = bomFileDir.listFiles(); |
| | | for (File bomFile : bomFileArr){ |
| | | String bomFileName = bomFile.getName(); |
| | | //解析excel |
| | | while (bomFileName.contains(".xls")){ |
| | | System.out.println("待解析的excel文件为:"+bomFileName); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void main(String[] args) throws IOException, InvalidFormatException { |
| | | File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\0940000072(BOM).xls"); |
| | | boolean exists = file.exists(); |
| | | System.out.println(exists); |
| | | Workbook workbook = WorkbookFactory.create(file); |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | System.out.println(lastRowNum); |
| | | } |
| | | } |