| | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelReader; |
| | | import com.alibaba.excel.read.builder.ExcelReaderBuilder; |
| | | import com.alibaba.excel.read.metadata.ReadSheet; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.chinaztt.mes.basic.util.DictUtils; |
| | | import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; |
| | | import com.chinaztt.mes.technology.excel.*; |
| | | import com.chinaztt.mes.technology.dto.StructureDTO; |
| | | import com.chinaztt.mes.technology.entity.StructureComponent; |
| | | import com.chinaztt.mes.technology.excel.StructureData; |
| | | import com.chinaztt.mes.technology.excel.StructureUploadListener; |
| | | import com.chinaztt.mes.technology.service.StructureService; |
| | | import com.chinaztt.ztt.admin.api.entity.SysDictItem; |
| | | 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; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | |
| | | private final StructureService structureService; |
| | | private final DictUtils dictUtils; |
| | | |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | /** |
| | | * 横着导入的导入方式 |
| | | * |
| | |
| | | */ |
| | | @PostMapping("/uploadExt") |
| | | public R uploadExt(@RequestParam("file") MultipartFile file) { |
| | | String key = "syncStructure_lock" + SecurityUtils.getUser().getId(); |
| | | if (redisTemplate.hasKey(key)) { |
| | | throw new RuntimeException("有导入任务正在处理"); |
| | | } |
| | | 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); |
| | | 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()); |
| | |
| | | * 竖着导入 |
| | | * |
| | | * @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(); |
| | | excelReader.read(readSheet); |
| | | } 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 |