From 4f4db2d34a1aaf1af4acb310774f51ffdef30d6a Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期一, 01 九月 2025 14:42:54 +0800 Subject: [PATCH] 保养标准:点检标准导入 --- src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java | 83 +++++++------ src/main/java/org/jeecg/modules/eam/constant/MaintenanceCategoryEnum.java | 4 src/main/java/org/jeecg/modules/eam/dto/MaintenanceStandardImport.java | 16 + src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandardDetail.java | 200 ++++++++++++++++---------------- src/main/java/org/jeecg/modules/eam/dto/WeekMaintenanceStandardImport.java | 8 5 files changed, 159 insertions(+), 152 deletions(-) diff --git a/src/main/java/org/jeecg/modules/eam/constant/MaintenanceCategoryEnum.java b/src/main/java/org/jeecg/modules/eam/constant/MaintenanceCategoryEnum.java index 0e7ac28..154ef59 100644 --- a/src/main/java/org/jeecg/modules/eam/constant/MaintenanceCategoryEnum.java +++ b/src/main/java/org/jeecg/modules/eam/constant/MaintenanceCategoryEnum.java @@ -5,6 +5,6 @@ */ public enum MaintenanceCategoryEnum { POINT_INSPECTION, //鐐规 - WEEK_MAINTENANCE, //淇濆吇 - ; + QUARTERLY_MAINTENANCE, //瀛f姤 + ANNUAL_MAINTENANCE, //骞存姤 } diff --git a/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java b/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java index 2fe4564..1546bcd 100644 --- a/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java +++ b/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java @@ -7,18 +7,13 @@ 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; @@ -33,7 +28,6 @@ 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; @@ -42,7 +36,10 @@ 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; @@ -274,6 +271,7 @@ params.setTitleRows(2); params.setHeadRows(1); params.setSheetNum(1); + params.setLastOfInvalidRow(23); params.setNeedSave(true); EamMaintenanceStandardRequest standardRequest = new EamMaintenanceStandardRequest(); try { @@ -287,8 +285,10 @@ 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); @@ -313,6 +313,7 @@ } return Result.ok("鏂囦欢瀵煎叆瀹屾垚锛�"); } + /** * 閫氳繃excel瀵煎叆鏁版嵁 @@ -343,7 +344,7 @@ 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); @@ -387,10 +388,17 @@ } 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())) { @@ -407,50 +415,43 @@ 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 diff --git a/src/main/java/org/jeecg/modules/eam/dto/MaintenanceStandardImport.java b/src/main/java/org/jeecg/modules/eam/dto/MaintenanceStandardImport.java index 451d990..94bf014 100644 --- a/src/main/java/org/jeecg/modules/eam/dto/MaintenanceStandardImport.java +++ b/src/main/java/org/jeecg/modules/eam/dto/MaintenanceStandardImport.java @@ -8,12 +8,18 @@ @Data public class MaintenanceStandardImport implements Serializable { - @Excel(name = "鍥惧彿", width = 15) - private Integer itemCode; - @Excel(name = "鐐规椤圭洰", width = 15) + @Excel(name = "NO", width = 15) + private String itemCode; + + @Excel(name = "閮ㄤ綅鍚嶇О", width = 15) private String itemName; - @Excel(name = "鐐规閮ㄤ綅", width = 15) + + @Excel(name = "鐐规鍐呭", width = 15) + private String subItemName; + + @Excel(name = "鐐规鏂规硶", width = 15) private String itemPart; - @Excel(name = "鐐规瑕佹眰", width = 15) + + @Excel(name = "鍩哄噯", width = 15) private String itemDemand; } diff --git a/src/main/java/org/jeecg/modules/eam/dto/WeekMaintenanceStandardImport.java b/src/main/java/org/jeecg/modules/eam/dto/WeekMaintenanceStandardImport.java index b7a6140..db81d8f 100644 --- a/src/main/java/org/jeecg/modules/eam/dto/WeekMaintenanceStandardImport.java +++ b/src/main/java/org/jeecg/modules/eam/dto/WeekMaintenanceStandardImport.java @@ -8,14 +8,14 @@ @Data public class WeekMaintenanceStandardImport implements Serializable { - @Excel(name = "搴忓彿", width = 15) + @Excel(name = "NO", width = 15) private Integer itemCode; - @Excel(name = "淇濆吇澶ч」鐩�", width = 15) + @Excel(name = "閮ㄤ綅鍚嶇О", width = 15) private String itemName; @Excel(name = "瀛愰」鐩�", width = 15) private String subItemName; - @Excel(name = "閮ㄤ綅/绫诲瀷", width = 15) + @Excel(name = "鐐规鍐呭", width = 15) private String itemPart; - @Excel(name = "淇濆吇瑕佹眰", width = 15) + @Excel(name = "鍩� 鍑�", width = 15) private String itemDemand; } diff --git a/src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandardDetail.java b/src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandardDetail.java index efd0f47..ceecea8 100644 --- a/src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandardDetail.java +++ b/src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandardDetail.java @@ -1,106 +1,106 @@ -package org.jeecg.modules.eam.entity; + package org.jeecg.modules.eam.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -import org.jeecg.modules.eam.dto.MaintenanceStandardImport; -import org.jeecg.modules.eam.dto.SecondMaintenanceStandardImport; -import org.jeecg.modules.eam.dto.ThirdMaintenanceStandardImport; -import org.jeecg.modules.eam.dto.WeekMaintenanceStandardImport; + import com.baomidou.mybatisplus.annotation.IdType; + import com.baomidou.mybatisplus.annotation.TableId; + import com.baomidou.mybatisplus.annotation.TableName; + import io.swagger.annotations.ApiModel; + import io.swagger.annotations.ApiModelProperty; + import lombok.Data; + import lombok.EqualsAndHashCode; + import lombok.experimental.Accessors; + import org.jeecg.modules.eam.dto.MaintenanceStandardImport; + import org.jeecg.modules.eam.dto.SecondMaintenanceStandardImport; + import org.jeecg.modules.eam.dto.ThirdMaintenanceStandardImport; + import org.jeecg.modules.eam.dto.WeekMaintenanceStandardImport; -import java.io.Serializable; -import java.util.Date; -/** - * @Description: 淇濆吇鏍囧噯鏄庣粏 - * @Author: jeecg-boot - * @Date: 2025-03-26 - * @Version: V1.0 - */ -@Data -@TableName("eam_maintenance_standard_detail") -@EqualsAndHashCode(callSuper = false) -@Accessors(chain = true) -@ApiModel(value="eam_maintenance_standard_detail瀵硅薄", description="淇濆吇鏍囧噯鏄庣粏") -public class EamMaintenanceStandardDetail implements Serializable { - - /**涓婚敭*/ - @TableId(type = IdType.ASSIGN_ID) - @ApiModelProperty(value = "涓婚敭") - private String id; - /**鍒涘缓浜�*/ - @ApiModelProperty(value = "鍒涘缓浜�") - private String createBy; - /**鍒涘缓鏃堕棿*/ - @ApiModelProperty(value = "鍒涘缓鏃堕棿") - private Date createTime; - /**鏇存柊浜�*/ - @ApiModelProperty(value = "鏇存柊浜�") - private String updateBy; - /**鏇存柊鏃堕棿*/ - @ApiModelProperty(value = "鏇存柊鏃堕棿") - private Date updateTime; - /**淇濆吇鏍囧噯ID*/ - @ApiModelProperty(value = "淇濆吇鏍囧噯ID") - private String standardId; - /**淇濆吇椤瑰簭鍙�*/ - @ApiModelProperty(value = "淇濆吇椤瑰簭鍙�") - private Integer itemCode; - /**閮ㄤ綅*/ - @ApiModelProperty(value = "閮ㄤ綅") - private String itemPart; - /**淇濆吇椤�*/ - @ApiModelProperty(value = "淇濆吇椤�") - private String itemName; - /**瀛愪繚鍏婚」*/ - @ApiModelProperty(value = "瀛愪繚鍏婚」") - private String subItemName; - /**妫�鏌ユ爣鍑嗘垨瑕佹眰*/ - @ApiModelProperty(value = "妫�鏌ユ爣鍑嗘垨瑕佹眰") - private String itemDemand; - /**淇濆吇瑕佹眰2*/ - @ApiModelProperty(value = "淇濆吇瑕佹眰2") - private String itemDemandAlias; - /**妫�鏌ユ柟娉�*/ - @ApiModelProperty(value = "妫�鏌ユ柟娉�") - private String checkMethod; + import java.io.Serializable; + import java.util.Date; + /** + * @Description: 淇濆吇鏍囧噯鏄庣粏 + * @Author: jeecg-boot + * @Date: 2025-03-26 + * @Version: V1.0 + */ + @Data + @TableName("eam_maintenance_standard_detail") + @EqualsAndHashCode(callSuper = false) + @Accessors(chain = true) + @ApiModel(value="eam_maintenance_standard_detail瀵硅薄", description="淇濆吇鏍囧噯鏄庣粏") + public class EamMaintenanceStandardDetail implements Serializable { + + /**涓婚敭*/ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "涓婚敭") + private String id; + /**鍒涘缓浜�*/ + @ApiModelProperty(value = "鍒涘缓浜�") + private String createBy; + /**鍒涘缓鏃堕棿*/ + @ApiModelProperty(value = "鍒涘缓鏃堕棿") + private Date createTime; + /**鏇存柊浜�*/ + @ApiModelProperty(value = "鏇存柊浜�") + private String updateBy; + /**鏇存柊鏃堕棿*/ + @ApiModelProperty(value = "鏇存柊鏃堕棿") + private Date updateTime; + /**淇濆吇鏍囧噯ID*/ + @ApiModelProperty(value = "淇濆吇鏍囧噯ID") + private String standardId; + /**淇濆吇椤瑰簭鍙�*/ + @ApiModelProperty(value = "淇濆吇椤瑰簭鍙�") + private Integer itemCode; + /**閮ㄤ綅*/ + @ApiModelProperty(value = "閮ㄤ綅") + private String itemPart; + /**淇濆吇椤�*/ + @ApiModelProperty(value = "淇濆吇椤�") + private String itemName; + /**瀛愪繚鍏婚」*/ + @ApiModelProperty(value = "瀛愪繚鍏婚」") + private String subItemName; + /**妫�鏌ユ爣鍑嗘垨瑕佹眰*/ + @ApiModelProperty(value = "妫�鏌ユ爣鍑嗘垨瑕佹眰") + private String itemDemand; + /**淇濆吇瑕佹眰2*/ + @ApiModelProperty(value = "淇濆吇瑕佹眰2") + private String itemDemandAlias; + /**妫�鏌ユ柟娉�*/ + @ApiModelProperty(value = "妫�鏌ユ柟娉�") + private String checkMethod; - public EamMaintenanceStandardDetail(){} + public EamMaintenanceStandardDetail(){} - public EamMaintenanceStandardDetail(MaintenanceStandardImport dto) { - this.itemCode = dto.getItemCode(); - this.itemPart = dto.getItemPart(); - this.itemName = dto.getItemName(); - this.itemDemand = dto.getItemDemand(); + public EamMaintenanceStandardDetail(MaintenanceStandardImport dto) { + this.itemCode = Integer.valueOf(dto.getItemCode()); + this.itemPart = dto.getItemPart(); + this.itemName = dto.getItemName(); + this.itemDemand = dto.getItemDemand(); + } + + public EamMaintenanceStandardDetail(WeekMaintenanceStandardImport dto) { + this.itemCode = dto.getItemCode(); + this.itemName = dto.getItemName(); + this.subItemName = dto.getSubItemName() + " " + (dto.getItemPart() == null ? "" : dto.getItemPart()); + this.itemDemand = dto.getItemDemand(); + } + + public EamMaintenanceStandardDetail(SecondMaintenanceStandardImport dto) { + this.itemCode = dto.getItemCode(); + this.itemName = dto.getItemName(); + this.itemPart = dto.getItemPart(); + this.itemDemand = dto.getItemDemand(); + this.itemDemandAlias = dto.getItemDemandAlias(); + this.checkMethod = dto.getCheckMethod(); + } + + public EamMaintenanceStandardDetail(ThirdMaintenanceStandardImport dto) { + this.itemCode = dto.getItemCode(); + this.itemName = dto.getItemName(); + this.itemPart = dto.getItemPart(); + this.itemDemand = dto.getItemDemand(); + this.itemDemandAlias = dto.getItemDemandAlias(); + this.checkMethod = dto.getCheckMethod(); + } } - - public EamMaintenanceStandardDetail(WeekMaintenanceStandardImport dto) { - this.itemCode = dto.getItemCode(); - this.itemName = dto.getItemName(); - this.subItemName = dto.getSubItemName() + " " + (dto.getItemPart() == null ? "" : dto.getItemPart()); - this.itemDemand = dto.getItemDemand(); - } - - public EamMaintenanceStandardDetail(SecondMaintenanceStandardImport dto) { - this.itemCode = dto.getItemCode(); - this.itemName = dto.getItemName(); - this.itemPart = dto.getItemPart(); - this.itemDemand = dto.getItemDemand(); - this.itemDemandAlias = dto.getItemDemandAlias(); - this.checkMethod = dto.getCheckMethod(); - } - - public EamMaintenanceStandardDetail(ThirdMaintenanceStandardImport dto) { - this.itemCode = dto.getItemCode(); - this.itemName = dto.getItemName(); - this.itemPart = dto.getItemPart(); - this.itemDemand = dto.getItemDemand(); - this.itemDemandAlias = dto.getItemDemandAlias(); - this.checkMethod = dto.getCheckMethod(); - } -} -- Gitblit v1.9.3