| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFSheet; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.usermodel.XSSFSheet; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.util.FileUtil; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.MaintenanceCategoryEnum; |
| | | import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; |
| | |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.entity.ImportParams; |
| | | import org.jeecgframework.poi.util.PoiPublicUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | params.setTitleRows(2); |
| | | params.setHeadRows(1); |
| | | params.setSheetNum(1); |
| | | params.setLastOfInvalidRow(23); |
| | | params.setNeedSave(true); |
| | | EamMaintenanceStandardRequest standardRequest = new EamMaintenanceStandardRequest(); |
| | | try { |
| | |
| | | standardRequest.setStandardName(standardRequest.getEquipmentName() + "点检标准"); |
| | | standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.POINT_INSPECTION.name()); |
| | | standardRequest.setEquipmentId(equipment.getId()); |
| | | |
| | | //读取保养明细内容 |
| | | List<MaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), MaintenanceStandardImport.class, params); |
| | | |
| | | //明细项 |
| | | List<EamMaintenanceStandardDetail> tableList = list.stream().map(EamMaintenanceStandardDetail::new).collect(Collectors.toList()); |
| | | standardRequest.setTableDetailList(tableList); |
| | |
| | | } |
| | | return Result.ok("文件导入完成!"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过excel导入数据 |
| | |
| | | continue; |
| | | } |
| | | standardRequest.setStandardName(standardRequest.getEquipmentName() + "保养标准"); |
| | | standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.WEEK_MAINTENANCE.name()); |
| | | standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.QUARTERLY_MAINTENANCE.name()); |
| | | standardRequest.setEquipmentId(equipment.getId()); |
| | | //读取保养明细内容 |
| | | List<WeekMaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), WeekMaintenanceStandardImport.class, params); |
| | |
| | | } |
| | | |
| | | Sheet sheet = book.getSheetAt(0); |
| | | //第一行读取 |
| | | Row row = sheet.getRow(0); |
| | | //第二行读取 |
| | | Row row = sheet.getRow(1); |
| | | //设备编码 |
| | | Cell equipmentCode = row.getCell(15); |
| | | Cell equipmentCode = row.getCell(5); |
| | | Cell targetCell = row.getCell(0); |
| | | //文件编码 |
| | | String fileCodeValue = getCellValue(targetCell); |
| | | if (fileCodeValue == null || fileCodeValue.trim().isEmpty()) { |
| | | throw new JeecgBootException("Excel【" + file.getOriginalFilename() + "】第二行第一列获取到的设备编号为空!"); |
| | | } |
| | | request.setFileCode(fileCodeValue.trim()); |
| | | if(CellType.NUMERIC.equals(equipmentCode.getCellType())) { |
| | | request.setEquipmentCode(String.valueOf((int) equipmentCode.getNumericCellValue())); |
| | | }else if(CellType.STRING.equals(equipmentCode.getCellType())) { |
| | |
| | | request.setInitialDate(new Date()); |
| | | } |
| | | //设备名称 |
| | | Cell equipmentName = row.getCell(13); |
| | | request.setEquipmentName(equipmentName.getStringCellValue()); |
| | | // Cell equipmentName = row.getCell(13); |
| | | // request.setEquipmentName(equipmentName.getStringCellValue()); |
| | | |
| | | //第二行读取 |
| | | row = sheet.getRow(1); |
| | | |
| | | row = sheet.getRow(4); |
| | | //保养周期 |
| | | Cell period = row.getCell(11); |
| | | Cell period = row.getCell(7); |
| | | if (CellType.NUMERIC.equals(period.getCellType())) { |
| | | request.setMaintenancePeriod((int) period.getNumericCellValue()); |
| | | } else { |
| | | //默认点检周期 1 |
| | | request.setMaintenancePeriod(1); |
| | | } |
| | | //文件编码 |
| | | Cell fileCode = row.getCell(13); |
| | | request.setFileCode(fileCode.getStringCellValue()); |
| | | |
| | | Map<String, PictureData> pictures; |
| | | if (isXSSFWorkbook) { |
| | | pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(0), (XSSFWorkbook) book); |
| | | } else { |
| | | pictures = PoiPublicUtil.getSheetPictrues03((HSSFSheet) book.getSheetAt(0), (HSSFWorkbook) book); |
| | | } |
| | | |
| | | if (CollectionUtil.isNotEmpty(pictures)) { |
| | | //只会存在一张图片 |
| | | PictureData pictureData = pictures.get(pictures.keySet().iterator().next()); |
| | | byte[] data = pictureData.getData(); |
| | | String fileName = request.getEquipmentCode() + "[" + request.getFileCode() + "]" + "." + pictureData.suggestFileExtension(); |
| | | FileUploadResult fileUploadResult = FileUtil.uploadFile(data, fileName); |
| | | if(fileUploadResult != null) { |
| | | List<FileUploadResult> fileList = request.getFileList(); |
| | | if(fileList == null) { |
| | | fileList = new ArrayList<FileUploadResult>(); |
| | | } |
| | | fileList.add(fileUploadResult); |
| | | request.setFileList(fileList); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("读取Excel信息失败:{}", e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 统一处理单元格值,支持数字和字符串类型 |
| | | * @param cell 单元格对象 |
| | | * @return 单元格的值,为 null 表示单元格无有效内容 |
| | | */ |
| | | private String getCellValue(Cell cell) { |
| | | if (cell == null) { |
| | | return null; |
| | | } |
| | | CellType cellType = cell.getCellType(); |
| | | if (cellType == CellType.NUMERIC) { |
| | | return String.valueOf((int) cell.getNumericCellValue()); |
| | | } else if (cellType == CellType.STRING) { |
| | | return cell.getStringCellValue(); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 读取Excel 第一行, 第二行的信息 |
| | | * @param file |