Fixiaobai
2023-11-09 3059430a0db3f75426e435c06090358646fc3792
mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java
@@ -32,9 +32,11 @@
import com.chinaztt.ztt.admin.api.feign.RemoteDictService;
import com.chinaztt.ztt.common.core.util.R;
import com.chinaztt.ztt.common.log.annotation.SysLog;
import com.chinaztt.ztt.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -60,6 +62,8 @@
   private final StructureService structureService;
   private final DictUtils dictUtils;
   private RedisTemplate redisTemplate;
   /**
    * 横着导入的导入方式
    *
@@ -68,29 +72,13 @@
    */
   @PostMapping("/uploadExt")
   public R uploadExt(@RequestParam("file") MultipartFile file) {
      //ExcelReader excelReader = null;
      //try {
      //   ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream());
      //   excelReader = excelReaderBuilder.build();
      //   List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();
      //   List<ReadSheet> readSheetList = new ArrayList<>();
      //   for (ReadSheet sheet : sheets) {
      //      ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(new StructureUploadExtListener(structureService)).build();
      //      readSheetList.add(readSheet);
      //   }
      //   excelReader.read(readSheetList);
      //} catch (IOException e) {
      //   e.printStackTrace();
      //   return R.failed(e.getMessage());
      //} finally {
      //   if (excelReader != null) {
      //      // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
      //      excelReader.finish();
      //   }
      //}
      String key = "syncStructure_lock" + SecurityUtils.getUser().getId();
      if (redisTemplate.hasKey(key)) {
         throw new RuntimeException("有导入任务正在处理");
      }
      ExcelReader excelReader = null;
      try {
         excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService, dictUtils)).build();
         excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService)).build();
         ReadSheet readSheet = EasyExcel.readSheet(0).build();
         ReadSheet readSheet2 = EasyExcel.readSheet(1).build();
         excelReader.read(readSheet,readSheet2);
@@ -110,27 +98,27 @@
    * 竖着导入
    *
    * @param file
    * @return
    */
   @PostMapping("/upload")
   public R simpleRead(@RequestParam("file") MultipartFile file) {
      ExcelReader excelReader = null;
      try {
         excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService, dictUtils)).build();
         ReadSheet readSheet = EasyExcel.readSheet(0).build();
         ReadSheet readSheet2 = EasyExcel.readSheet(1).build();
         excelReader.read(readSheet,readSheet2);
      } catch (IOException e) {
         e.printStackTrace();
         return R.failed(e.getMessage());
      } finally {
         if (excelReader != null) {
            // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
            excelReader.finish();
         }
      }
      return R.ok();
   }
//    * @return
//    */
//   @PostMapping("/upload")
//   public R simpleRead(@RequestParam("file") MultipartFile file) {
//      ExcelReader excelReader = null;
//      try {
//         excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService)).build();
//         ReadSheet readSheet = EasyExcel.readSheet(0).build();
//         ReadSheet readSheet2 = EasyExcel.readSheet(1).build();
//         excelReader.read(readSheet,readSheet2);
//      } catch (IOException e) {
//         e.printStackTrace();
//         return R.failed(e.getMessage());
//      } finally {
//         if (excelReader != null) {
//            // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
//            excelReader.finish();
//         }
//      }
//      return R.ok();
//   }
   /**
    * 根据零件号查询默认BOM