From b848451e8889fea12ce40b7818c1b8d84b50ea02 Mon Sep 17 00:00:00 2001
From: lxw <810412026@qq.com>
Date: 星期四, 01 九月 2022 13:41:07 +0800
Subject: [PATCH] 权限管理组合操作

---
 src/main/java/com/whyc/controller/MaterialController.java |  131 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/whyc/controller/MaterialController.java b/src/main/java/com/whyc/controller/MaterialController.java
index 493682c..ecd5d62 100644
--- a/src/main/java/com/whyc/controller/MaterialController.java
+++ b/src/main/java/com/whyc/controller/MaterialController.java
@@ -1,14 +1,29 @@
 package com.whyc.controller;
 
 import com.whyc.dto.Response;
+import com.whyc.pojo.DocUser;
+import com.whyc.pojo.Material;
+import com.whyc.pojo.MaterialApproving;
 import com.whyc.service.MaterialService;
+import com.whyc.util.ActionUtil;
+import com.whyc.util.CommonUtil;
+import com.whyc.util.FileUtil;
+import com.whyc.util.Zip4jUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
 
 @Api(tags = "鐗╂枡绠$悊")
 @RestController
@@ -39,4 +54,112 @@
         return service.getMaterialLimit(subCode,subName,subModel,pageCurr,pageSize);
     }
 
+    @PostMapping
+    @ApiOperation(value = "鏂板",notes = "瑙f瀽杩斿洖鐨勭粷瀵硅矾寰�,闇�瑕佸洖浼犲埌瀛楁fileUrl")
+    public Response add(@RequestBody List<Material> materialList){
+        return service.add(materialList);
+    }
+
+    @PostMapping("zipParse")
+    @ApiOperation("zip瑙f瀽")
+    public Response zipParse(MultipartFile file) throws IOException, InvalidFormatException {
+        List<MaterialApproving> list = new LinkedList<>();
+        Response response = new Response();
+        //妫�鏌ユ槸鍚︿负zip
+        boolean isZip = Zip4jUtil.checkZipFileParam(file);
+        if(!isZip){
+            return response.set(1,false,"涓婁紶鐨勬枃浠舵牸寮忎笉鏄痾ip");
+        }
+        //zip瀛樺偍璺緞:doc_file/material_submit/${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 filePath = rootFile + File.separator + "material_submit" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
+        File parentFile = new File(filePath);
+        String originalFilename = file.getOriginalFilename();
+        File zipFile = new File(filePath+File.separator+ originalFilename);
+        if(!zipFile.exists()){
+            zipFile.mkdirs();
+        }
+        file.transferTo(zipFile);
+        //瑙e帇鏂囦欢澶�
+        Zip4jUtil.unPackZip(zipFile,null,filePath);
+        //閬嶅巻瑙e帇鍚庣殑鏂囦欢澶硅矾寰�,瑙f瀽excel
+        System.out.println(filePath);
+        List<String> fileList = new ArrayList<>();
+        fileList = FileUtil.getStaticFilePath(parentFile,fileList);
+        for (int i = 0; i < fileList.size(); i++) {
+            String fileTempUrl = fileList.get(i);
+            //鏌ヨ鍒皒ls鏁版嵁
+            if(fileTempUrl.contains(".xls")){
+                File fileTemp = new File(fileTempUrl);
+                Workbook workbook = null;
+                workbook = WorkbookFactory.create(fileTemp);
+                List<? extends PictureData> allPictures = workbook.getAllPictures();
+                //鍙栫涓�涓猻heet琛�
+                Sheet sheet = workbook.getSheetAt(0);
+                int lastRowNum = sheet.getLastRowNum();
+                //鍙栫涓夎,骞朵互绗笁琛屽紑濮�
+                Row rowTemp = sheet.getRow(1);
+                short lastCellNum = rowTemp.getLastCellNum();
+                //鍏堝崟鐙幏鍙栦骇鍝佸瀷鍙峰拰鐗堟湰鍙�/鍒嗙被
+                Row row = sheet.getRow(1);
+                String type = row.getCell(1).getStringCellValue();
+
+                Row row2 = sheet.getRow(2);
+                String productModel = row2.getCell(5).getStringCellValue();
+                Row row3 = sheet.getRow(3);
+                String productVersion = row3.getCell(5).getStringCellValue();
+                for (int l = 8; l < lastRowNum-1; l++) {
+                    Cell cellTemp = sheet.getRow(l).getCell(1);
+                    cellTemp.setCellType(Cell.CELL_TYPE_STRING);
+                    if(cellTemp.getStringCellValue().equals("")){
+                        break;
+                    }
+                    MaterialApproving approving = new MaterialApproving();
+                    approving.setCreateDate(new Date());
+
+                    for (int m = 2; m < lastCellNum; m++) {
+                        row = sheet.getRow(l);
+                        Cell cell = row.getCell(m);
+                        String cellValue = null;
+                        int cellValueInt = 0;
+                        Double cellValueDouble = null;
+                        if(m == 3){
+                            //cellValueDouble = cell.getNumericCellValue();
+                            //DecimalFormat decimalFormat = new DecimalFormat("0");
+                            //cellValue = decimalFormat.format(cellValueDouble);
+                            cell.setCellType(Cell.CELL_TYPE_STRING);
+                            cellValue = cell.getStringCellValue();
+                        }
+                        else if(m ==7){
+                            cellValueDouble = cell.getNumericCellValue();
+                        }
+                        else {
+                            cellValue = cell.getStringCellValue();
+                        }
+
+                        switch (m){
+                            case 2:{approving.setCategory(cellValue);}break;
+                            case 3:{approving.setSubCode(cellValue);}break;
+                            case 4:{approving.setSubName(cellValue);}break;
+                            case 5:{approving.setSubModel(cellValue);}break;
+                            case 6:{approving.setUnit(cellValue);}break;
+                            case 7:{approving.setQuantity(cellValueDouble.intValue());}break;
+                            case 8:{approving.setProducer(cellValue);}break;
+                            case 9:{approving.setNotes(cellValue);}break;
+                        }
+                    }
+                    list.add(approving);
+                }
+            }
+        }
+        for (MaterialApproving MaterialApproving : list) {
+            if(MaterialApproving.getSubName()==null ||MaterialApproving.getSubName().equals("")){
+                return response.set(1,false,"鎷掔粷瑙f瀽,excel鏂囦欢涓褰曞寘鍚悕绉颁负绌虹殑璁板綍");
+            }
+        }
+        return response.setII(1,true,list,filePath);
+    }
 }

--
Gitblit v1.9.1